Working with a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Working with a file
# 1  
Old 09-27-2005
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
# 2  
Old 09-27-2005
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).
# 3  
Old 09-27-2005
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

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

2. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

3. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

4. Red Hat

Nslookup working but ping not working at windows client

Hi Team we have created a DNS server at RHEL6.2 environment in 10.20.203.x/24 network. Everything is going well on linux client as nslookup, ping by host etc in entire subnet. We are getting problem in windows client as nslookup working as well but not ping. all the firewall is disabled and... (5 Replies)
Discussion started by: boby.kumar
5 Replies

5. Shell Programming and Scripting

Working out days of the week and processing file in 3 working days

Hi guys i need advice on the approach to this one...... I have a file say called Thisfile.20130524.txt i need to work out from the date 20130524 what day of the week that was and then process the file in 3 working days. (so not counting saturday or sunday....(will not worry about bank... (2 Replies)
Discussion started by: twinion
2 Replies

6. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

7. UNIX for Dummies Questions & Answers

Working with file-names

Hello forum, I am new to shellscripting. My first goal is to write a script that verifies that for each file in one path there is an associated one in another path. The association is deviated by a distinct 'part' of the filename(s). Therefore I wanted to work with substitution. Here is... (3 Replies)
Discussion started by: danielandross
3 Replies

8. Shell Programming and Scripting

put working directory in file

how to put pwd in my file my working directory is /usr/my_dir below my file aaaaaa bbbbbb so output file become /usr/my_dir aaaaaa bbbbbb (2 Replies)
Discussion started by: zulabc
2 Replies

9. UNIX for Dummies Questions & Answers

Working of file command

Hi, we are using sun solaris 9 os. I want to know how the file command works? How does it differentiate text files, data files and other files ? Is there any relationship between environmental variables and file command? (2 Replies)
Discussion started by: rprajendran
2 Replies

10. Shell Programming and Scripting

Working with a Text file

I need help with a shell script. I have a flat file with lines begining with 'newuser' in it along with other lines which do not have 'newuser' in the begining of the line newuser (followed by 10 spaces) user1 user2 The script should accomplish following things a. Ask the user for input... (1 Reply)
Discussion started by: aajmani
1 Replies
Login or Register to Ask a Question