Home > Software design >  cut function on specific line
cut function on specific line

Time:12-02


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.)

CodePudding user response:

I think you can use awk to achieve what you are looking for. I havent used it in a while but just toss a man awk into your terminal and you should get some good examples.

CodePudding user response:

Using shell utilities head, tail and cut:

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

or a sed one-liner:

sed '1s/..//' file
  • Related