ctsgnb
1
Hi
I was just wondering ... what is the most simple and/or efficient way you suggest in awk, to "shift" fields to left ?
(let's say we are not interested by the N first field but we want to print all N+1 and more fields , until the end of line)
Of course i want to get rid off any potential leading FS (those at beginning of line)
One way to remove the first 3 fields:
awk '{sub(".*" $3 FS,"")}1' file
1 Like
ctsgnb
3
awk lack that shift
command
Alas, no shift operator in AWK
ctsgnb
5
Yep, cruel lack of that shift
thing
I was dreaming about a "kind of" work around like
$0=system (set -- $0 ; shift 3 )
but this will of course also fail ... grrrrr
Yep , I think sub is the best option. Sub alternative:
awk 'sub(".*"$4,$4)'
A bit longer but should shift and clear FS in beginning of line (start at field 2)
#!/bin/ksh
cat <file name> | awk '{
ct=split($0,a)
ftime=1
for(x=2;x<ct;x++){
if(ftime == 1){
out_val=a[x]
ftime=0
}else{
out_val=out_val " " a[x]
}
}
printf("%s\n",out_val)
}'