LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk help (https://www.linuxquestions.org/questions/linux-newbie-8/awk-help-4175501206/)

santosh0782 04-10-2014 05:59 AM

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

pan64 04-10-2014 06:42 AM

you can simply remove the first part:
awk ' gsub("^[^|]+[|]", "") ' test.txt

grail 04-10-2014 07:38 AM

I would have probably just used sed for a simple removal:
Code:

sed 's/[^|]*\|//' test.txt

Madhu Desai 04-10-2014 07:49 AM

Code:

$ awk -F"|" '{OFS="|"; $1=""; print $0}' test.txt

santosh0782 04-11-2014 01:46 AM

Thanks a lot to all.. :-) all options are working fine.

grail 04-11-2014 02:15 AM

Please remember to mark as SOLVED once you have a solution.


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