Operating System - HP-UX
1834187 Members
2657 Online
110064 Solutions
New Discussion

scripting! , how to do this ?

 
SOLVED
Go to solution
rveri
Super Advisor

scripting! , how to do this ?

Hi All ,

I have this : data1.txt
--------
44%
53%
77%
61%
1%
3%
45%
49%
------

How to get this out put like this:
-----
44
53
77
61
1
3
45
49
-----

Thanks in advance.
8 REPLIES 8
RAC_1
Honored Contributor
Solution

Re: scripting! , how to do this ?

tr -d '\%' < "your_file"
There is no substitute to HARDWORK
Raj D.
Honored Contributor

Re: scripting! , how to do this ?

hi,

You can use this command:

# cat data1.txt | sed 's/%/ /'

44
53
77
61
1
3
45
49


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Muthukumar_5
Honored Contributor

Re: scripting! , how to do this ?


# awk -F"%" '{ print $1; }' < inputfile > outputfile
# cut -d"%" -f1 < inputfile > outputfile

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: scripting! , how to do this ?

To update in the same file itself then,

# perl -pi -e 's/%//' filename

Lots of ways to do it.

--
Muthu
Easy to suggest when don't know about the problem!
rveri
Super Advisor

Re: scripting! , how to do this ?

Thanks all ,
Muthu though # perl -pi -e 's/%//' filename , command not giving output. Rest all orking fine.

Muthukumar_5
Honored Contributor

Re: scripting! , how to do this ?

hi,

perl -pi -e 's/%//' filename

will update in the file itself.

Example:

# cat filename
45%
35%

# perl -pi -e 's/%//' filename
# cat filename
45%
35%

It is not needing any temporary files to do this action.

If you don't want then simply as,

# perl -p -e 's/%//' filename (without -i)

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: scripting! , how to do this ?

oops,

# perl -pi -e 's/%//' filename
# cat filename
45
35

will remove % and update in the same file.

--
Muthu
Easy to suggest when don't know about the problem!
rveri
Super Advisor

Re: scripting! , how to do this ?

Thanks Muthukumar ,

Its working!!