The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Working of file command rprajendran UNIX for Dummies Questions & Answers 2 05-13-2008 11:19 AM
truncate file script is not working mvenkat_in Shell Programming and Scripting 3 10-23-2007 10:01 PM
Invoke URL's from file and comment with # symbol which are not working gsp UNIX for Dummies Questions & Answers 0 08-22-2007 11:55 PM
KSH redirect of dynamic egrep to file not working. markw Shell Programming and Scripting 4 02-28-2007 03:40 AM
Working with a Text file aajmani Shell Programming and Scripting 1 09-09-2005 10:02 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-27-2005
Registered User
 

Join Date: Sep 2005
Posts: 15
Working with a file

I am new UNIX user. I am using HPUX.
Here is a sample file I am working with.

01-253850,170464,84,59555
01-325100,169793,81,95734
01-325470,120737,81,28893
01-358250,169995,81,51698

Is there any way for me to pull out each section individually and copy it to a new file. I want to separate the sections by the commas.

ex. the first line would be separated:

01-253850 This would be put into its own file
170464 This would be put into its own file
84 This would be put into its own file
59555 This would be put into its own file

Thanks,

Nick
Reply With Quote
Forum Sponsor
  #2  
Old 09-27-2005
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Modified from Ygor's

Code:
#!/bin/ksh
while read line
do
IFS=","
eval set $line
if [[ $1 != "" ]]
then
p1=$1
p2=$2
p3=$3
p4=$4
echo $p1 >> pfile1
echo $p2 >> pfile2
echo $p3 >> pfile3
echo $p4 >> pfile4
shift
fi
done < your-input-file-here
Modify this to your needs - this is assuming that you want all the positions in the same file (all of the position 4 of each line in pfile4).
Reply With Quote
  #3  
Old 09-27-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Or...
Code:
$ cat filein
01-253850,170464,84,59555
01-325100,169793,81,95734
01-325470,120737,81,28893
01-358250,169995,81,51698

$ awk -F, '{for(x=1;x<=NF;x++)print $x>"fileout." x}' filein

$ head fileout.?
==> fileout.1 <==
01-253850
01-325100
01-325470
01-358250

==> fileout.2 <==
170464
169793
120737
169995

==> fileout.3 <==
84
81
81
81

==> fileout.4 <==
59555
95734
28893
51698
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0