LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-02-2017, 01:55 AM   #1
farahjihan1993
LQ Newbie
 
Registered: Mar 2017
Posts: 1

Rep: Reputation: Disabled
Remove column using awk


wanted to drop first 3 column;

This is my data;

DETAIL 02032017

Name Gender State School Class
A M Melaka SS D
B M Johor BB E
C F Pahang AA F
EOF 3
I want my data like this:

DETAIL 02032017
School Class
SS D
BB E
AA F
EOF 3


This is my current command that I get mycommandoutput:

awk -v date="$(date +"%d%m%Y")" -F\| 'NR==1 {h=$0; next}
{file="TEST_"$1"_"$2"_"date".csv";
print (a[file]++?"": "DETAIL"date"" ORS h ORS) $0 > file} END{for(file in a) print "EOF " a[file] > file}' testing.csv

Can anyone help me?

Thank you

I want to remove first three column
 
Old 03-02-2017, 02:31 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
please use [code]here comes your script[/code] to keep formatting of your original code.
how is this awk related to your goal? Do you want to modify testing.csv or the file created by this awk, or something else?
Is this your homework?
 
Old 03-02-2017, 06:01 AM   #3
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
To me, it looks like what you infact want to do is just print the last two columns as opposed to removing the first three. Such as:

Code:
$ echo abc def ghi jkl | awk '{print $(NF-1) " " $NF }'
ghi jkl
Anyways, the easy way to do what you asked is just to set the fields to nothing

Code:
$ echo abc def ghi jkl | awk '{$1=$2=""; print $0}'
  ghi jkl

Last edited by r3sistance; 03-02-2017 at 06:04 AM.
 
  


Reply



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
Remove Column from .CSV using AWK command gaurvrishi Linux - Newbie 13 04-03-2015 11:14 AM
[SOLVED] AWK fill column from previuos line column akeka Programming 4 01-30-2013 07:16 PM
[SOLVED] Not able to extract last column from awk vinaytp Linux - Newbie 4 05-20-2011 04:27 AM
awk multiple column into single column ilukacevic Programming 49 07-19-2010 07:23 PM
[ask awk] remove certain row in a column dhodho Programming 18 06-08-2010 09:36 AM

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

All times are GMT -5. The time now is 08:52 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
Open Source Consulting | Domain Registration