user3329128
user3329128

Reputation: 41

Removing 1st char from the strings

I have a file name abc.TXT. The contents of the file are

./pub/index.html
./manifest.bak
./manifest.rel
./ns/GSCT_ASNShipmentInfo_E1/node.idf
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml.bak
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/node.ndf
./ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml

I want to remove the .(dot) from each line and save the content to a new file bcd.TXT. The content in bcd.TXT should be

  /pub/index.html
  /manifest.bak
  /manifest.rel
  /ns/GSCT_ASNShipmentInfo_E1/node.idf
  /ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml.bak
  /ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/node.ndf
  /ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml

Upvotes: 2

Views: 69

Answers (4)

Vijay
Vijay

Reputation: 67231

Using perl:

perl -pe 's/\.//' abc.TXT > bcd.TXT

For in place replacement:

perl -pi -e 's/\.//' abc.TXT

Upvotes: 0

BMW
BMW

Reputation: 45243

Using awk

awk '{sub(/^\./,X)}1' abc.TXT > bcd.TXT

Upvotes: 0

jaypal singh
jaypal singh

Reputation: 77105

fedorqui's answer will remove any first character. So if you are not sure if it is a . then you can tell sed to remove only if you see a .

Using:

sed 's/^\.//' abc.TXT > bcd.TXT

tells sed that if first character of my file (denoted with ^) is a literal . (denoted with \.), then replace it with nothing.

If you want to make changes in your existing file you can use -i option. This will make the changes in your file.

Upvotes: 1

fedorqui
fedorqui

Reputation: 289755

With sed:

$ sed 's/.//' abc.TXT > bcd.TXT
$ cat bcd.TXT
/pub/index.html
/manifest.bak
/manifest.rel
/ns/GSCT_ASNShipmentInfo_E1/node.idf
/ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml.bak
/ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/node.ndf
/ns/GSCT_ASNShipmentInfo_E1/E1/svcUpdateVR01ForOP/flow.xml

sed s/.// replaces a character with nothing once every line. That is, it removes the first character.

Upvotes: 1

Related Questions