Help me with the cleaning of a file using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me with the cleaning of a file using shell script
# 1  
Old 05-21-2010
Help me with the cleaning of a file using shell script

Dear,

I have an input file and need to clean and get the following output:
Code:
ATM1/0/0,19072000,97848000
ATM1/0/1,18015000,83270000
ATM1/0/2,16879000,89491000
ATM1/0/3,21684000,122096000



Input file:

Code:
show interface ATM1/0/0 | inc rate
  Interface ATM1/0/0 queueing strategy: PXF Class-based
  5 minute input rate 19072000 bits/sec, 10970 packets/sec
  5 minute output rate 97848000 bits/sec, 13338 packets/sec
AJU-SE-10K-01show interface ATM1/0/1 | inc rate
  Interface ATM1/0/1 queueing strategy: PXF Class-based
  5 minute input rate 18015000 bits/sec, 9942 packets/sec
  5 minute output rate 83270000 bits/sec, 11337 packets/sec
AJU-SE-10K-01show interface ATM1/0/2 | inc rate
  Interface ATM1/0/2 queueing strategy: PXF Class-based
  5 minute input rate 16879000 bits/sec, 9813 packets/sec
  5 minute output rate 89491000 bits/sec, 12380 packets/sec
AJU-SE-10K-01show interface ATM1/0/3 | inc rate
  Interface ATM1/0/3 queueing strategy: PXF Class-based
  5 minute input rate 21684000 bits/sec, 12436 packets/sec
  5 minute output rate 122096000 bits/sec, 15820 packets/sec

Thanks for the help
# 2  
Old 05-21-2010
Code:
$> awk '/ATM/ {a=$2} /input rate/ {b=$5} /output rate/ {print a,b,$5}' OFS=, infile
ATM1/0/0,19072000,97848000
ATM1/0/1,18015000,83270000
ATM1/0/2,16879000,89491000
ATM1/0/3,21684000,122096000

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 05-21-2010
You can read records from a file line by line via while loop and give input of this file.
then either can cut the specific words or by awk can print the specific word from this file.

for example
Code:
{ while read rec; do
     getLine=`echo $rec | awk '{print $1;}'`
if [ "${getLine}" = "Valid" ] ; then
line2=`echo $rec|cut -c13-76`
getYear=`echo $rec|cut -c73-76`
getMonth=`echo $rec|cut -c53-55`
echo "getYear-getMonth: $getYear-$getMonth"
done } < temp.txt



---------- Post updated at 06:34 PM ---------- Previous update was at 06:28 PM ----------

zaxxon you are genius. pls give me some tuition man

Last edited by Scott; 05-21-2010 at 10:01 AM.. Reason: Added code tags
This User Gave Thanks to KuldeepSinghTCS For This Post:
# 4  
Old 05-21-2010
Thank zaxxon. This is the biggest and best unix web forum, as has professionals like you.

The code worked perfectly.

---------- Post updated at 10:26 AM ---------- Previous update was at 10:25 AM ----------

Thank you for your attention, KuldeepSinghTCS.
Your script was very well prepared and certainly will use in my projects.
hugs.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

3. Shell Programming and Scripting

Need a script for automatically cleaning up /var/spool/cups directory

Hi Friends, Actually in an linux server , there was printer jobs files occupying more space in /var/spool/cups so i want a script for deleting the files once in two week since i need the latest two weeks files. Thanks in advance..Waiting for the script. (2 Replies)
Discussion started by: Mohamed Thamim
2 Replies

4. Shell Programming and Scripting

cleaning the file

Hi, I have a file with multiple rows. each row has 8 columns. Column 8 has entries separated by commas. I want to exclude all the rows in which column 8 has more than 3 commas. 1234#0/1 - ABC_1234 3 ATGCATGCATGC HHHIIIGIHVF 1 49:T>C,60:T>C,78:C>A,76:G>T,65:T>G Thanks, Diya (3 Replies)
Discussion started by: Diya123
3 Replies

5. Shell Programming and Scripting

File cleaning

HI , I am getting the source data as below. Source Data CDR_Data,,,,, F1,F2,F3,F4,F5,F6 5,5,6,7,8,7 6,6,g,,, 7,7,76,,, 8,8,gt,,, 9,9,df ,d,d,d ,,,,, (4 Replies)
Discussion started by: wangkc
4 Replies

6. Shell Programming and Scripting

Data Cleaning in a file

Hi , I have the below source data, I need to clean the data in 2nd,4th,5th columns. Source Data RECORD,CASH_TRANS,BEJING,AUG2011/CASH_TRANS,Y/N150/CASH_TRANS,N/201108 RECORD,CASH_TRANS,INDIA,AUG2011/CASH_TRANS,Y/NC110/CASH_TRANS,N/201108... (7 Replies)
Discussion started by: mora
7 Replies

7. UNIX for Dummies Questions & Answers

cleaning up spaces from fixed width file while converting to csv file

Open to a sed/awk/or perl alternative so that i can stick command into my bash script. This is a problem I resolve using a combination of cut commands - but that is getting convoluted. So would really appreciate it if someone could provide a better solution which basically replaces all... (3 Replies)
Discussion started by: svn
3 Replies

8. Shell Programming and Scripting

how to read dbf file in shell script and to convert dbf file usinf shell script

Hi all, I am new to shell scripting. I have dbf file and I need to convert it into csv file. OR, can i read the fields from a .dbf file and OR seprate the records in dbf file and put into .csv or txt. Actually in the .dbf files I am getting , the numbers of fields may vary in very record and... (6 Replies)
Discussion started by: gauara
6 Replies

9. UNIX for Dummies Questions & Answers

Cleaning file system

Hello all, I have a crontab entry to clean up a file system once a week that is used as tmp directory. 00 12 * * 0 find /mytmp -mtime +2 -exec rm {} \; The job starts ok but I always get an error message in mails because it is a file system and there is a directory lost+found that should... (1 Reply)
Discussion started by: qfwfq
1 Replies
Login or Register to Ask a Question