Posts Tagged With: line

Iterate a Text File in Bash

Tagged with: , , ,

This is how you iterate thru a text file outputting a line at a time in Bash shell scripting.


IFS=$'\n'; for i in $(cat FILE.TXT); do echo "$i"; done
1 Comment »

Add Line Numbers

Tagged with: , , , , , ,

Use this command to add line numbers to a text file…


sed = filename.txt | sed 'N;s/\n/\t/' > filename_number.txt
3 Comments »

Delete Leading Whitespace

Tagged with: , , , , ,

Delete leading whitespace (spaces/tabs/etc) from beginning of each line


ruby -pe 'gsub(/^\s+/, "")' < file.txt
1 Comment »

Sort by Line Length

Tagged with: , , , , ,

Sort file by line length. Original Article…


cat /etc/passwd | awk '{print length, $0}' | sort -n | awk '{$1=""; print $0 }'
1 Comment »

Delete all \n chars in a file…

Tagged with: , , , , , , , ,

Delete all \n chars in a file…


tr -d "\n" 
No Comments »

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
1 Comment »

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 »