Issue
I am looking for a way to delete the 3rd column of every other line in a text file. Sample input:
4444 pm 7654 army 3687 anywhere 5650 infection
7332 thesis 0638 nasa 3976 condition 0738 los
3549 partners 7584 fee 3930 move 6535 friends
5693 matter 8801 visits 5350 grid 8917 honest
4039 facing 5453 cp 6101 bedrooms 5268 ford
Desired output:
4444 pm army 3687 anywhere 5650 infection
7332 thesis 0638 nasa 3976 condition 0738 los
3549 partners fee 3930 move 6535 friends
5693 matter 8801 visits 5350 grid 8917 honest
4039 facing cp 6101 bedrooms 5268 ford
I am aware of two commands.
awk '{print $3}' input.txt
sed '1~2d' input.txt
But I am not sure how to combine them.
Looking forward to any sort of help or suggestions.
Solution
This might work for you (GNU sed):
sed 's/\S\+//3;n' file
Delete the 3rd column, print the result and fetch the next line, repeat.
Answered By - potong Answer Checked By - Robin (WPSolving Admin)