LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 05: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, 06:42 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,450

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

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
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, 07:49 AM   #4
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
Code:
$ awk -F"|" '{OFS="|"; $1=""; print $0}' test.txt
 
1 members found this post helpful.
Old 04-11-2014, 01: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 01:47 AM.
 
Old 04-11-2014, 02:15 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,516

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
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 12:46 AM
[SOLVED]Wierd AWK behavior / AWK not reading first line. Involar Linux - Newbie 9 11-28-2012 10:53 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 10:49 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:29 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