LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2014, 06:59 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
awk help


Hi,

i want to retrieve data from 2nd column to last column from a file test.txt , the below command is working, however can we make it more simpler?

awk -F '|' '{OFS="|";print $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12}' test.txt
 
Old 04-10-2014, 07:42 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,516

Rep: Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436
you can simply remove the first part:
awk ' gsub("^[^|]+[|]", "") ' test.txt
 
1 members found this post helpful.
Old 04-10-2014, 08:38 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
I would have probably just used sed for a simple removal:
Code:
sed 's/[^|]*\|//' test.txt
 
1 members found this post helpful.
Old 04-10-2014, 08:49 AM   #4
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 516

Rep: Reputation: 139Reputation: 139
Code:
$ awk -F"|" '{OFS="|"; $1=""; print $0}' test.txt
 
1 members found this post helpful.
Old 04-11-2014, 02:46 AM   #5
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Thanks a lot to all.. :-) all options are working fine.

Last edited by santosh0782; 04-11-2014 at 02:47 AM.
 
Old 04-11-2014, 03:15 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Please remember to mark as SOLVED once you have a solution.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 01:46 AM
[SOLVED]Wierd AWK behavior / AWK not reading first line. Involar Linux - Newbie 9 11-28-2012 11:53 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 11:49 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 10:06 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM


All times are GMT -5. The time now is 10:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration