Bash ‘must know’ tips
July 13, 2010, 1:08 am
Filed under: nerd, open source

Usually I read a lot of bash tips, codes, snippets, but some tips are hard to find, let see 2 tips:

Read Line

The ideia is, read each line of a file using bash, some people use terrible ways to do this job.

Bash has a simple way, $(< filename)

echo $(< file.txt)

Apparently the command did’n work, but the fact’s, the command worked, but printed line by line without ‘\n’.

This for show how to work with each line.

for i in $(<file); do echo $i; done

Rename only the extension

This is simple, some tasks need a in file and a out file, the two files can be different, if we need a ‘for’ we need create a good number of files.

Instead of create something like foo.txt and foo.txt.xml, you can create one foo.xml.

Let’s use ${//}  to improve your  work.

$variable =
echo ${variable/foo/bar}

Inside a for, is awesome:

for i in */*.xml; do xml2xsd $i ${i/xml/xsd}; done



1 Comment so far
Leave a comment

twoextended familyConsignmentrevolting disgustingnuclearnfamilytwo Inventoryextended familyfive hundred five hundredtwoextended familyTheextende Click

Comment by sanchezmoreno66312

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: