Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awk + Need to print everything (all rest fields) except $1 and $2

Tags:

awk

filtering

I have the following file and I need to print everything except $1 and $2 by awk

File:

INFORMATION DATA 12 33 55 33 66 43 
INFORMATION DATA 45 76 44 66 77 33 
INFORMATION DATA 77 83 56 77 88 22
...

the desirable output:

 12 33 55 33 66 43 
 45 76 44 66 77 33 
 77 83 56 77 88 22
...
like image 838
yael Avatar asked Jun 15 '10 14:06

yael


People also ask

What does $1 $2 indicate in awk file?

The awk variables $1 or $2 through $nn represent the fields of each record and should not be confused with shell variables that use the same style of names. Inside an awk script $1 refers to field 1 of a record; $2 to field 2 of a record.

What is awk '{ print $1 }'?

awk '{print $1}' information. txt prints the first column. Then the output of that command (which you saw earlier on) is piped, using the pipe symbol | , to the head command, where its -1 argument selects the first line of the column. If you wanted two lines printed, you'd do: awk '{print $1}' information.txt | head -2.

What does awk print $NF do?

The “NF” AWK variable is used to print the number of fields in all the lines of any provided file. This built-in variable iterates through all the lines of the file one by one and prints the number of fields separately for each line.


2 Answers

Well, given your data, cut should be sufficient:

cut -d\  -f3- infile
like image 63
Dimitre Radoulov Avatar answered Nov 14 '22 15:11

Dimitre Radoulov


Although it adds an extra space at the beginning of each line compared to yael's expected output, here is a shorter and simpler awk based solution than the previously suggested ones:

awk '{$1=$2=""; print}'

or even:

awk '{$1=$2=""}1'
like image 29
jlliagre Avatar answered Nov 14 '22 14:11

jlliagre