?
Solved

Splitting a text file into seperate text files.

Posted on 2001-06-26
5
Medium Priority
?
192 Views
Last Modified: 2010-04-21
I get a text file with a long list of filenames that looks like this:

a52372,CH-A-00-00-02-00A-040A-A
a58758,CH-A-00-00-03-00A-012B-A
a58759,CH-A-00-00-03-00A-012B-A
a58760,CH-A-00-00-03-00A-012B-A
a65855,CH-A-06-40-00-00A-010A-A
a58883,CH-A-06-40-01-00A-540A-A
a58884,CH-A-06-40-01-00A-540A-A
a65855,CH-A-06-40-01-00A-540A-A
a62128,CH-A-06-40-01-00A-540A-A
a65817,CH-A-08-40-00-00A-030A-A
a65818,CH-A-08-40-00-00A-030A-A
a53077,CH-A-08-40-00-00A-030A-A

I need to be able to send all the files with CH-A-00 to one file and CH-A-06 to another and CH-A-08 to another and so on. The number in the 13th and 14th position determines what file they need to go. I can't grep those positions because they change and I never know what they're going to be. The letters in front of those postions change to.

Is there a way to cut that number out and save it to a variable then use the variable in a for loop or if statement then goto the next line?

jas
0
Comment
Question by:scuzz1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 400 total points
ID: 6228696
Maybe you could try a ksh script something like this:

#!/bin/ksh

while read line ; do
  print $line
  file=`print $line | awk '{ print substr($0,13,2) }'`
  print $file
  print $line >> $file
 done<file.txt
0
 

Author Comment

by:scuzz1
ID: 6228806
That looks like what I want to do but where do you tell it what file it is reading from?
0
 

Author Comment

by:scuzz1
ID: 6228825
Never mind the last comment. I figured it out. I'm going to try to work in the textfiles I need. I think this will work.
0
 

Author Comment

by:scuzz1
ID: 6228914
Excellent. I was really stuck. I couldn't get the thing to slow down and read the file one line at a time.

Thanks much,

jas
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 6229527
You're welcome.  Just glad I could help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question