From recent posts, we have tried to remove the first word by statically specifying the matching string fields using awk and cut.
What if we need to remove the first word but retain the 2nd word up to Nth word of a line from a text file?
Here's a real quick and easy of dynamically looping awk to achieve the above effects.
Now let us try removing the first word while retaining the 2nd word up to the Nth word of a line from any text files.
# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now we have removed the first word while retaining the rest from 2nd to Nth word of a line
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# cat testfile.txt | awk '{for(i=2;i<=NF;i++) printf ("%s ", $i);}'
output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
we have removed the first word while retaining the rest from 2nd to Nth word of a line
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That is all folks.
Subscription
Categories
- HowTos (612)
- Linux Devices (40)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
▼
2008
(2301)
-
▼
February
(25)
- HowTo: Extract Lines That Started With Matching St...
- HowTo: Delete All Thumbs.db Recursively
- HowTo: Handy Linux Network Diagnostic Tool
- HowTo: Display Lines That Starts With A Given String
- HowTo: Find And Count JPG Files Recursively
- HowTo: Do Awk with Loop
- HowTo: Strip Out First Word of Line from Text Files
- HowTo: Highlight Matching Grep Results
- HowTo: GNOME Commander File Manager
- HowTo: Install Plone CMS on Fedora
- HowTo: Thumbnail A Website From Linux Command Term...
- HowTo: Advanced Two-Pane File Manager
- HowTo: Two-Pane GUI File Manager
- Slash Proc - File System Utilities
- HowTo: Drop Down Linux Terminal Console
- HowTo: Image Magics with ImageMagick
- HowTo: Convert JPG Image Files to MPG Video Files
- HowTo: Alternative Way to Convert GIF to PNG
- HowTo: Lock X While Root With ScreenSaver
- HowTo: Encrypted Bandwidth-Efficient Linux Backup ...
- HowTo: Install Java IcedTea on Fedora 8
- HowTo: Simultaneous Install of Sun Java and Java I...
- HowTo: Install K9Copy on Fedora
- HowTo: More of Fedora Themes Package
- HowTo: European Language Fonts Installation on Fedora
-
▼
February
(25)
Monday, February 25, 2008
HowTo: Do Awk with Loop
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy
0 comments:
Post a Comment