- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Interesting Shell Script Requirement
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 01:47 AM
05-09-2006 01:47 AM
-----------------------------------
1
2
3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
-----------------------------------
The requirement is to extract information from the 4th line and write it to a file as comma separated values 4, 5, 6, 7
And similary for the next two lines(each line goes to a different file.)
Is there a good way to do this?
Any help in this regard would be highly appreciated.
Regards,
Anurag
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 01:59 AM
05-09-2006 01:59 AM
Re: Interesting Shell Script Requirement
awk 'NR==$2 {print $0}' $1 | tr " " "," > $3
Usage:
script.sh line_numb input_file output_file
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 02:00 AM
05-09-2006 02:00 AM
Re: Interesting Shell Script Requirement
assuming your initial data file is called a.dat. Also that there are no trailing spaces.
This command translates all spaces into commas and writes the new data to file b.dat.
tr " " "," < a.dat > b.dat
will create
1
2
3
4,5,6,7
8,9,10,11
12,13,14,15
16,17,18,19
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 02:05 AM
05-09-2006 02:05 AM
Re: Interesting Shell Script Requirement
NR<7&&NR>3 {for (idx=1;idx=NF;idx++) {printf("%s,",$idx);}
printf("\n");}
awk -f pull.awk < inputfile > outputfile
That takes care of the comma seperated part.
What is the file name syntax that you are using for each file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 02:29 AM
05-09-2006 02:29 AM
Re: Interesting Shell Script Requirement
you can try with:
head -n n_of_line file_source|tail -1|sed 's/ /,/g' > file_dest
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 02:46 AM
05-09-2006 02:46 AM
Solutionawk 'NR>3{gsub(" ",",");print $0}' yourdata.dat | split -l1 - outfil
This will generate files outfilaa, outfileab, etc. One file per line.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 02:51 AM
05-09-2006 02:51 AM
Re: Interesting Shell Script Requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 05:12 AM
05-09-2006 05:12 AM
Re: Interesting Shell Script Requirement
yourcommand |
awk -v OFS=, 'NR>3 {out="/tmp/outf"++x;for (i=1;i
will produce files /tmp/outf* .
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 05:20 AM
05-09-2006 05:20 AM
Re: Interesting Shell Script Requirement
All the solution were damn good......
I will handle the naming convention for the output files myself.
Thanks a lot again
Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2006 05:23 AM
05-09-2006 05:23 AM