Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove '-' from the string

Status
Not open for further replies.

cognos11

MIS
Nov 19, 2003
40
US
i have a file from which i need to select those records that match like this.

'3456-8796-0987-2345'

To do is i used simple grep command like this
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]" > file.txt

Now once i get these records i want to remove the
'-' string from the 19 char field above and the result should like

'3456879609872345'



 
The sed way:
sed -n '/[0-9]\{4\}-[0-9]\{4\}-[0-9]\{4\}-[0-9]\{4\}/s/-//gp' /path/to/input >output



Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Without using grep:
[tt]
BEGIN{d4="[0-9][0-9][0-9][0-9]";
pat=d4 "-" d4 "-" d4 "-" d4 }
$0 ~ pat {gsub(/-/,""); print}
[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top