![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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
|
||||
| Google The UNIX and Linux Forums |