Problems editing file with awk in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems editing file with awk in bash script
# 1  
Old 03-04-2011
PHP Problems editing file with awk in bash script

Hello dear users, here I have a script to manipulate .csv files that are like this originally:

Quote:
Txxx-Px_14_0_0==xxx-o6_0_0,26886_27498_7,TGCUY01,26886,xxx,27498,xx,PortChannel,39813,Po0_14_0_0,,So6_0_0,,0,Links TGCUY01,xxxx- (xxx)
And I need to make a script to delete certain fields. Each field is separated with a comma.

So, here is my script (at least a part of it):

Quote:
#!/bin/bash
echo -e "Type name of document:"
read DOCUMENT
echo "Processing."
nawk -F"," '{print $1","$2","$3","$4","$7","$8","$9","$10","$13","$14","$15","$16}' $DOCUMENT >> "$DOCUMENT"tmp
nawk '{gsub("'=='","");print }' "$DOCUMENT"tmp >> "$DOCUMENT"final
rm "$DOCUMENT"tmp
echo "Successfully processed."
Field $1 is composed of a name, and then a "==$5-$12".
I need to delete that part. Is always like Txxx-Px_14_0_0==xxx-o6_0_0,26886_27498_7 and I need to delete Ex. ==xxx-o6_0_0,26886_27498_7 dynamically.

gsub works only for characters that don't change (or at least for me).
I tried making a variable for $5-$12 but it didn't work.

Can you help me please Smilie?
# 2  
Old 03-04-2011
Post desired output for that sample line.
# 3  
Old 03-04-2011
Quote:
Txxx-Px_14_0_06,TGCUY01,26886,xxx,27498,xx,PortChannel,39813,Po0_14_0_0,,So6_0_0,,0,Links TGCUY01,xxxx- (xxx)
Something like this.

PS: Forgot to post that I'm using Solaris 10 and nawk, not awk (to use gsub). But I don't think it would change something.
# 4  
Old 03-04-2011
Try:
Code:
perl -pe 's/==[^,]+,[^,]+//' $DOCUMENT >> "$DOCUMENT"final

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 03-04-2011
It seems that is working now. Many, MANY thanks from Argentina.
# 6  
Old 03-04-2011
do you mean this?
Code:
awk 'BEGIN{FS="[=,]"}{printf $1",";for(i=5;i<=18;i++) printf "%s,",$i}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed problems - Bash Script

Hi I keep getting the following error sed: -e expression #1, char 32: unterminated `s' command sed: -e expression #1, char 35: unterminated `s' command sed: -e expression #1, char 35: unterminated `s' command whenever I use the following bash script #! /bin/bash... (2 Replies)
Discussion started by: spbr
2 Replies

2. Shell Programming and Scripting

Parsing and Editing a json file with bash script

I am trying to automate editing of a json file using bash script. The file I initially receive is { "appMap": { "URL1": { "name": "a" }, "URL2": { "name": "b" }, "URL3": { "name": "c" }, } WHat I would like to do is replace... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

3. Shell Programming and Scripting

editing file with awk cut and sed

HI All, I am new to unix. I have a file would like to do some editing by using awk, cut and sed. Could anyone help? This file contain 100 lines. There are one line for example: 2,"102343454",5060,"579668","579668","579668","SIP",,,"825922","035885221283026",1,268,"00:59:00.782 APR 17... (2 Replies)
Discussion started by: mimilaw
2 Replies

4. Shell Programming and Scripting

Execution problems with BASH Shell Script

Hi I need help with my coding , first time I'm working with bash . What i must do is check if there is 3 .txt files if there is not 3 of them i must give an error code , if al three is there i must first arrange them in alphabetical order and then take the last word in al 3 of the .txt files... (1 Reply)
Discussion started by: linux newb
1 Replies

5. Shell Programming and Scripting

Execution Problems with bash script

Hello, can someone please help me to fix this script, I have a 2 files, one file has hostname information and second file has console information of the hosts in each line, I have written a script which actually reads each line in hostname file and should grep in the console file and paste the... (8 Replies)
Discussion started by: bobby320
8 Replies

6. Web Development

bash script editing my apache config files

okay i'm going to try to say this uber-simple: I use dropbox (file-sync service). in order for dropbox sync files, they must be its children eg. somewhere under /home/jzacsh/Dropbox]. I want to now use it to keep my development files in sync across my machines: easy: just move my dev. files... (2 Replies)
Discussion started by: jzacsh
2 Replies

7. UNIX for Dummies Questions & Answers

Pls help me with file editing using awk

Hi all, Pls help me with file editing using awk. I have a text file with the below format. "STANDARD VOLUME ","2009","BUX","V","JCBH49","NF", 001413 "VENDOR MATERIAL-STD ","2009","BUX","V","JCBH49","NF", 009948 "INBOUND TRANS-STD ... (2 Replies)
Discussion started by: srinivas.maddy
2 Replies

8. Shell Programming and Scripting

Editing File using awk/sed

Hello Awk Gurus, Can anyone of you help me with the below problem. I have got a file having data in below format pmFaultyTransportBlocks ----------------------- 9842993 pmFrmNoOfDiscRachFrames ----------------------- NULL pmNoRecRandomAccSuccess -----------------------... (4 Replies)
Discussion started by: Mohammed
4 Replies

9. Shell Programming and Scripting

Editing the File using Awk

I have input file that is having below text 098769 178902 234678 I want to modify the input file like below. '098769', '178902', '234678' Can you please help to get this. I tried but i am not getting this. (3 Replies)
Discussion started by: awk_beginner
3 Replies

10. Shell Programming and Scripting

File editing using awk

Hi All, I have a file, say test.dat which is "|" separated. It has 50K records in it. One of the field in the file has the data in the format 'mm/dd/yyyy'. I need to edit the file by changing the format to 'yyyy/mm/dd' in the same field where as the rest of the data remain untouched. Please... (2 Replies)
Discussion started by: rinku11
2 Replies
Login or Register to Ask a Question