Reputation: 131
I have a file named test.txt which has the following content
123,2,1
I want to print the contents of the file without "123,"
I used the following
awk -F, '{print substr($0, index($0, $2))} text.txt'
It doesn't work properly tho, it prints 23,2,1
But when I run it for this text '123,5,1' , it works without a problem (it prints 5,1
)
Upvotes: 2
Views: 2265
Reputation: 41446
Another awk
echo '123,2,1' | awk -F, '{$1="";sub(/,/,"")}1' OFS=,
2,1
Removes the first field, then the separator.
Upvotes: 3
Reputation: 99909
Use cut
:
cut -d, -f2- file
-d,
uses ,
as delimiter, and -f2-
prints fields 2 to last.
Upvotes: 2
Reputation: 77085
You can use sub()
function and remove the first field regardless of what it is.
$ echo '123,2,1' | awk '{sub(/[^,]+,/,"")}1'
2,1
$ echo '23,2,1' | awk '{sub(/[^,]+,/,"")}1'
2,1
Upvotes: 3