Unix script required

I have a file 123.txt which is

aasaasas=1
bsasasasasa=2
sawqas=3

I want my output to be
1
2
3

I am new to scripting can some1 help me out.

Can you show us what you've tried so far?

read about the cut command

Hi kamaraj,

can u tell the same one with the help of sed command..

thank u

sed basic replacement

sed -i 's/old/new/g' filename

if you issue the above command, it will modify the word "old" with "new" word (where ever the old word appear - globally (g))

sed man page
Man Page for sed (OpenSolaris Section 1) - The UNIX and Linux Forums

For this question, we need to introduce a regular expression (in the place of old ) to remove the characters upto =

I have very little bit knowledge on "sed" command. I have tried with below command..

sed -n 's/^.*=\(.\)/\1/p'

Please correct me...

 
bash-3.00$ !sed
sed -n 's/^.*=\(.\)/\1/p' test
1
2
3
214
bash-3.00$ cat test
aasaasas=1
bsasasasasa=2
sawqas=3
abc=214

your command gives the correct ouput.

 
bash-3.00$ sed 's/.*=//' test
1
2
3
214

2 Likes

itkamaraj, could you explain, what is that mean? I really want to know about regex.

  • (star)Repeats the previous item zero or more times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is not matched at all
    Regular Expressions Reference - Basic Syntax

.*= this will match the aasaasas=, bsasasasasa=, ..........

so i am replacing that with empty sed 's/.*=//'

1 Like

How do we do it with Cut.

How do you achieve the same with Cut.

Ok thanks for your explanation.

did u try with cut ?

did u read the man page of cut ?

read about the -d in the cut command

try this

 
awk -F\= '{print $NF}' 123.txt
 
bash-3.00$ cat test
aasaasas=1
bsasasasasa=2
sawqas=3
abc=214
bash-3.00$ cut -d"=" -f2 test
1
2
3
214

-d = delimeter ( we are setting it as = )
-f2 = second field.

From man page :