awk + Need to print everything (all rest fields) except $1 and $2
17,878
Solution 1
Well, given your data, cut should be sufficient:
cut -d\ -f3- infile
Solution 2
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'
Solution 3
$ cat t
INFORMATION DATA 12 33 55 33 66 43
INFORMATION DATA 45 76 44 66 77 33
INFORMATION DATA 77 83 56 77 88 22
$ awk '{for (i = 3; i <= NF; i++) printf $i " "; print ""}' t
12 33 55 33 66 43
45 76 44 66 77 33
77 83 56 77 88 22
Solution 4
danbens answer leaves a whitespace at the end of the resulting string. so the correct way to do it would be:
awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' filename
Solution 5
If the first two words don't change, probably the simplest thing would be:
awk -F 'INFORMATION DATA ' '{print $2}' t
Author by
yael
Updated on July 07, 2022Comments
-
yael almost 2 years
I have the following file and I need to print everything except
$1
and$2
byawk
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 ...