Posts Tagged With: line

Text type convert

Tagged with: , , , , , , ,

Convert a text file format from MSDOS to UNIX


dos2unix input_file output_file
No Comments »

Find Duplicate Lines

Tagged with: , , , , ,

Sort contents of two files by viewing only duplicate line


sort file1 file2 | uniq -d
No Comments »

Sort and Unique

Tagged with: , , , , , ,

Sort contents of a file and remove repeated lines


sort file.txt | uniq
1 Comment »

Remove Even Lines

Tagged with: , , , ,

This command removes all the even lines from the file given as the argument


cat example.txt|awk 'NR%2==1'
No Comments »

View some lines in a file

Tagged with: , , , ,

View from 1th to 5th line


sed -n '1,5p;5q' example.txt
No Comments »

Remove Empty Characters at End of Lines

Tagged with: , , , ,

Remove empty characters at the end of each row


sed -e 's/ *$//' file.txt
No Comments »

First Two Lines

Tagged with: , , , ,

View first two lines of a file


head -2 file

tail -2 file # for last 2 lines
No Comments »

Double Space a File using Sed

Tagged with: , , , , , , ,

Add a \n after every line in a file using the sed command…


sed G 
No Comments »

Get the First Line of Command Output in Shell

Tagged with: , , , , ,

Get just the first line of the output of a command…


<command>|head -n1

ls -1|head -n1
No Comments »

Replace \n with another String

Tagged with: , , , ,

The command to convert all \n in a file to another string - very useful for list code generation.


perl -ne 's/\\n/\',\'/g;print;' file.txt>new.txt
No Comments »