Shell Scripting

Hey I have a data in the file named as outputFile.txt. The data is in the format
123456,12345678912345,400,09/09/09,INACTIVE.

I want this output without commas ie

12345612345678912345400090909INACTIVE.

Please tell me what to do and clear explain all the terms, as I am new to it.

bash-3.00$ nawk -F"," '{ for (i=1;i<=NF;i++) {if(i==NF) {printf("%s\n",$NF)} else printf ("%s",$i)}}' /tmp/myfile
1234561234567891234540009/09/09INACTIVE
1234561234567891234540009/09/09INACTIVE
1234561234567891234540009/09/09INACTIVE

bash-3.00$ cat /tmp/myfile
123456,12345678912345,400,09/09/09,INACTIVE
123456,12345678912345,400,09/09/09,INACTIVE
123456,12345678912345,400,09/09/09,INACTIVE

read each word (seperated by comma) and just print it. If it is the last word, then print new line character ("\n")

---------- Post updated at 02:35 PM ---------- Previous update was at 02:33 PM ----------

you dont want / (forward slash) also ?

Hey itkamaraj
Thanks!!

Can u explain me what is F and NF and whats the logic behind this.

or simply use the sed command

 
bash-3.00$ sed 's/,//g' /tmp/myfile
1234561234567891234540009/09/09INACTIVE
1234561234567891234540009/09/09INACTIVE
1234561234567891234540009/09/09INACTIVE

---------- Post updated at 02:44 PM ---------- Previous update was at 02:41 PM ----------

NF - Number of Fields
Awk - A Tutorial and Introduction - by Bruce Barnett
F - Field Seperator
Awk - A Tutorial and Introduction - by Bruce Barnett

Hey thanks, but both are not working
Below is the code.
In the code I am asking the user to enter the Location Code and Account number and status, then I am using Loaction and Account Number to match into a inputFile.txt and then writing the data to an output file. Also I have to write 400, date and status at the end of the line.

#!/bin/sh
#Author : Sameer Pandey
#Copyrights: Anybody can modify and make it work better.

echo "Input Location Code"
read locationCode

echo "Input the Account number"
read accountNumber

echo "Input the Status"
read status

>outFile.txt
chmod 777 outFile.txt
>outputFile.txt
chmod 777 outputFile.txt
egrep -i "$locationCode" inputFile.txt > tempFile.txt
grep -i "$accountNumber" tempFile.txt > outFile.txt

rm tempFile.txt

echo "400" >> outFile.txt
date "+%y/%m/%d" >> outFile.txt
echo $status >> outFile.txt

awk 'ORS=NR%1?RS:","' RS="\n" outFile.txt >> outputFile.txt

sed 's/,//g' outputFile.txt

cat outputFile.txt >> outputFilefinal.txt

echo "Processes Completed successfully"

Kindly look at the code and tell me where is the error.

post the outFile.txt contents

use sed -i

 
sed -i 's/,//g' outputFile.txt

Thank You very very much. It worked. :slight_smile: :slight_smile:

I just wanted to ask one thing more.
If suppose I wanted to read the file until I encounter a comma, then write that data into another file. How will I do that?