![]() |
|
|
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 |
| Turn For Loop into While Loop | cbo0485 | Shell Programming and Scripting | 7 | 08-04-2009 01:58 PM |
| Using variables created sequentially in a loop while still inside of the loop [bash] | DeCoTwc | Shell Programming and Scripting | 2 | 06-23-2009 05:59 PM |
| Is there a better way I could have run this loop. (For loop with two variables) | DeCoTwc | Shell Programming and Scripting | 2 | 03-27-2009 02:07 AM |
| while loop inside while loop | panknil | Shell Programming and Scripting | 0 | 01-07-2008 12:49 PM |
| how to get the similar function in while loop or for loop | trynew | Shell Programming and Scripting | 3 | 06-17-2002 12:09 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using AWK in a for loop
Hello,
I am trying to use AWK to print only the first field of numerous text files, and then overwrite these files. They are of the format 1*2,3,4,5. I have tried the following code (using tcsh): Code:
foreach f (file1 file2 file3)
cat $f | awk -F'*' '{print $1}' > $f
end
On a side note, I have tried a similar method using cut: Code:
foreach f (file1 file2 file3) cat $f | cut -d'*' -f1 > $f end Thank you for your help, -Jahn |
|
||||
|
I'd personally get rid of the brackets around the foreach, but i dont know tcsh so it may be a requirement. It should work doing
Code:
for file in file1 file2 file3 ; do awk -F'*' '{print $1}' < $file > $file ; done
Quote:
|
|
||||
|
Here is what worked for me:
Code:
foreach f (*)
awk -F'*' '{print $1}' $f > {$f}_temp
mv {$f}_temp $f
end
Thanks again for your help, guys! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|