tags:

views:

106

answers:

5

Remove first comma on each line in a file. I presume sed is needed.

+2  A: 

Yes, sed will do it.

sed s/,// < filename
Beta
This will only remove first first comma :(
vehomzzz
Really? It works for me.
Beta
Redirection isn't necessary.
Dennis Williamson
@Dennis Williamson true, but I realized that too late; I can't edit now while the behavior is still in doubt.
Beta
+7  A: 

sed

sed -i.bak 's/,//' file

awk

awk '{sub(",","")}1' file >temp; mv temp file

shell

while read -r line
do
 echo "${line/,/}"
done <"file" > temp
mv temp file
ghostdog74
What is this .bak business?
kzh
check the sed man page. its for backing up the file.
ghostdog74
+1  A: 

For first comma:

sed '/,//' < file

If first comma is first character:

sed '/^,//' < file

kzh
My answer is contingent if you are using a *NIX OS. If not, well I am sure somebody will post a powershell answer.
kzh
+1  A: 

Yes,

first comma sed '/,//' < file

first character that is a comma sed '/^,//' < file

USEFUL ONE-LINE SCRIPTS FOR SED

TMB
A: 
sed '/^,//' < file
WisdomFusion
awk '{sub(",","")}1' file >temp; mv temp file
WisdomFusion
How to format code in comments? **bold**
WisdomFusion
this checks for a string with a comma as its first character and remove it. its is not the same as "first" comma
ghostdog74
sed '/,//' < file
WisdomFusion