I need to remove all spaces from the 3rd line onwards. The spaces in the first two lines should not be removed. Any option to exclude the first two lines in sed or awk?
Input file:
This is the first line
This is the second line
This is the third line
This is the fourth line
This is the fifth line
This is the sixth line
....
....
....
Output expected
This is the first line
This is the second line
Thisisthethirdline
Thisisthefourthline
Thisisthefifthline
Thisisthesixthline
....
....
....
The application we support was migrated from IBM z/OS platform to Ubuntu with training on Ubuntu for 2 weeks only on basic commands. The man for sed in our installation is having has limited information, hence reaching out to Ubuntu experts for help on solutions when we are short on time.
We had used a combination of head, tail and sed commands in our script to achieve this but knew it was not the efficient way. For now, we are the dumb guys with Mainframe knowledge working on Ubuntu until we practice more on this environment in our free time.
Using sed:
Explanation:
1,2!
for all lines except lines 1 and 2s/ //g
removes all spaces (globally) in the non-excluded lines (from the third line onwards).Results of
sed '1,2!s/ //g' InputFile.txt
:Using any awk: