Cut Function on Specific Line

Cut Function on Specific Line

I have a file in unix, say as below:
$ cat file
1.this is the test file.
The file have data related to recent survey.

The requirement is to cut the first two characters only from the 1st line and print rest of the content of the file as it is, I have tried the cut command for same..

$ cut -c 3- file
this is the test file.
e file have data related to recent survey.

but its removing the 2 characters from each line, is there any way to implement the cut only on the first line or any other command we can use to get the required result (also the first two characters could be anything which need to remove, not particularly 1.)

1 Answer

Using shell utilities head, tail and cut:

head -n1 file | cut -c3-; tail -n+2 file

or a sed one-liner:

sed '1s/..//' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.