![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| use awk to read variable length csv | shweta_d | Shell Programming and Scripting | 3 | 06-18-2007 02:16 AM |
| Fixed Length records- Korne Shell Program. | nrajesh_2009 | Shell Programming and Scripting | 4 | 04-11-2007 12:41 PM |
| Select records based on search criteria on first column | shashi_kiran_v | UNIX for Dummies Questions & Answers | 2 | 12-02-2005 01:49 PM |
| Length of a variable | karyn1617 | Shell Programming and Scripting | 3 | 02-08-2005 06:41 PM |
| creating a fixed length output from a variable length input | r1500 | Shell Programming and Scripting | 2 | 12-03-2003 01:09 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using awk to search variable length records
New to awk and need some help. I have a script that I would like to make more compact. I want to read a file and grab every field, from every record, except the last field. The records are variable length and have varying number of fields. A record will have at least two fields, but can have many more. Here is what I am currently using. Can someone provide a compact solution? Thanks.
awk '{ print $1 }' sftplist.txt >> users.txt awk '{ print $2 }' sftplist.txt >> users.txt awk '{ print $3 }' sftplist.txt >> users.txt awk '{ print $4 }' sftplist.txt >> users.txt awk '{ print $5 }' sftplist.txt >> users.txt awk '{ print $6 }' sftplist.txt >> users.txt awk '{ print $7 }' sftplist.txt >> users.txt awk '{ print $8 }' sftplist.txt >> users.txt awk '{ print $9 }' sftplist.txt >> users.txt awk '{ print $10 }' sftplist.txt >> users.txt This gives me what I want, but then I have a lot of cleanup after it, like removing blank lines and lines that contained the last field when I didn't want the last field. |
|
||||
|
Thanks for the suggestion, but your solution still provides me the last field of the record of which I have to cleanup from the file. It's not that big of a deal to perform the cleanup, I just like to keep my scripts as compact as possible and not perform unnecessary processing.
![]() |
|
||||
|
Sure,
Anything to help. Here is sftplist.txt user3 user1 user2 /mydir/next/dir1 user2 /mydir/next/dir2 user1 user4 /staging/next/dir1 Output users.txt user3 user1 user2 user2 user1 user4 Hope this helps. I can manage the sort -u afterwards. ![]() |
|
||||
|
Here is what I have,
rev sftplist.txt | cut -d ' ' -f2- | rev | tr ' ' '\n' > users.txt This is what I get. tr: 0653-712 The combination of options and String parameters is not legal. Usage: tr [ -[c|C] | -[c|C]ds | -[c|C]s | -ds | -s ] [-A] String1 String2 tr { -[c|C]d | -[c|C]s | -d | -s } [-A] String1 Last edited by synergy_texas; 08-21-2008 at 06:51 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|