Asked By
Emily Wills
0 points
N/A
Posted on - 08/16/2011
I have a script which creates text file whose content is as below and this file gets automatically created by putting the output of  some 'find' command into this text file :
/home/emilly
/home/emilly/abc.dat
/home/emilly/cds.txt
i want to add the piece of code in the same script which removes the first line from the file i.e. /home/emilly only.
Please suggest some useful command.
Removal of first line in text file using unix script
Look emily it is very easy thing to do.
Suppose you have a file named 'my_book.txt'. and you want to remove the first line from it.
Type the following command/script
# Line 1. To change the name of file 'my_book.txt'
 mv my_book.txt my_book_temp.txt Â
# Line 2Â . To delete first line from 'my_book_temp.txt' and send the rest of the content in the file 'my_book.txt'
sed 1d my_book_temp.txt > mky_book.txt
# Line 3. To remove the temporary file named 'my_book_temp.txt'
rm my_book_temp.txt
The text written in bold are the command which can be written in your script file.
The file name 'my_book.txt' can be replaced with the file name from which you want to delete one line.
Removal of first line in text file using unix script
Hi Emily
Removing first line from a file can be done easily using shell command.
‘tail’ command can be used for that purpose.
To display the file without first line, use this command
tail –n +2 /home/emilly
In case you are not aware of tail command, tail will accept the number of lines to be displayed from the end of a file.
For example, if you give tail -5 filename, last 5 lines of the file will be displayed.
Please follow these steps to achieve your goal.
1) tail –n +2 /home/emilly > /home/emilly.bk
2)Â mv /home/emilly.bk /home/emilly