Handy one-liners

While creating websites I often find the need to manipulate files in all sorts of ad-hoc ways.

Things that are hard to do by hand, but you don't want to write a whole program for - you'll just use it once and throw it away.

Linux/Unix excels at this sort of task - there is a rich selection of tools and plenty of ready made recipes.

From:

http://www.ibm.com/developerworks/linux/library/l-p101/

I often use


> cat test
aaa
bbb
ccc
ddd
aaa
> perl -pi -e's/aaa/bbb/' test
> cat test
bbb
bbb
ccc
ddd
bbb

http://student.northpark.edu/pemente/sed/sed1line.txt

gives me a way to print out just the lines near an error is being generated (handy when there is one error line in a gigabyte of data)


sed -n '7560,7570p' my_big_file.txt

Though day to day grep, find, locate and thier friends usually do all I need.

I tried working on Windows a while ago - but found I just couldn't work effectively without these tools.

Tags

Post new comment

Got something to add - just enter a comment
all other fields are optional.

Your email address will not be published.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.