Parse file with '=' sign


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse file with '=' sign
# 1  
Old 04-10-2009
Parse file with '=' sign

Hi,

Can anyone help me parse the code bellow. I have a file with several lines. I ant to put an 'X' on the lines that ONLY have an '=' in them ignoring comma's, spaces etc..

So:
/*
,

systems.menuLabel.new=New
systems.menuLabel.new.mnemonic=N
*/

Would look like:
/*
,

systems.menuLabel.new=NewX
systems.menuLabel.new.mnemonic=NX
*/

Also if I have a line:
/*
systems.subsystems.servers=Name,Servers,Description,Work Servers available on the network
*/

I want it to come out like:
/*
Hi all and thanks. I used your code zaxxon and it worked fine.

I was wondering if I can change that now to use '=' sign instead of a commas?

So:
/*
,

systems.menuLabel.new=New
systems.menuLabel.new.mnemonic=N
*/

Would look like:
/*
,

systems.menuLabel.new=NewX
systems.menuLabel.new.mnemonic=NX
*/

Also if I have a line:
/*
systems.subsystems.servers=Name,Servers,Description,Work Servers
*/

to come out like:
/*
systems.subsystems.servers=NameX,ServersX,DescriptionX,Work ServersX
*/

Thank you!
# 2  
Old 04-10-2009
nawk -f jas.awk myFile

jas.awk:
Code:
BEGIN {
  FS=OFS="="
  FSlist=","

  SUF="X"

  COMs="^[/][*]"
  COMe="^[*][/]"
}

$0 ~ COMs {comm++}
$0 ~ COMe {comm--}

comm && NF>=2 {
   n=split($2, valA, FSlist)
   for(i=1; i <=n; i++)
     $2=(i==1) ? valA[i] SUF : $2 FSlist valA[i] SUF
}
1


Last edited by vgersh99; 04-10-2009 at 11:04 AM..
# 3  
Old 04-10-2009
How can i run this?

bash: nawk: command not found is what I get Smilie
# 4  
Old 04-10-2009
use either 'awk' or 'gawk' if available.
# 5  
Old 04-10-2009
I used awk - thanks.

However it not seem to do anything, when I ran it it just printed out the text but there was no 'X' at the end of it.
# 6  
Old 04-10-2009
given jas.txt:
Code:
/*
systems.subsystems.servers=Name,Servers,Description,Work Servers
*/

/*
,

systems.menuLabel.new=New
systems.menuLabel.new.mnemonic=N
*/

running:
Code:
nawk -f jas.awk jas.txt

produces:
Code:
/*
systems.subsystems.servers=NameX,ServersX,DescriptionX,Work ServersX
*/

/*
,

systems.menuLabel.new=NewX
systems.menuLabel.new.mnemonic=NX
*/

Is there anything wrong with the output?
# 7  
Old 04-10-2009
Code:
sed -e '/=/s/,/X,/' -e '/=/s/$/X/' file_in

kiss...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Enter carriage return in xml file after each tag (> sign)

I have an xml file which is generated in a single line an looks like this <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Batch_Id="1999996" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><some data....><some data....>closing lines...... I need to have a separate line... (3 Replies)
Discussion started by: vx04
3 Replies

2. Shell Programming and Scripting

New to Perl Mail @ sign search and replace in a file

HI I'm terribly new to perl .. I;ve been trying to use this command to search and replace entries in a file I tried this and it works perl -p -i -e 's/old/new/' filename Problem is that I have a list of email addresses and I need to serach and replace the entire email address as my... (5 Replies)
Discussion started by: mnassiri
5 Replies

3. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

4. Shell Programming and Scripting

Shell not parsing $ sign from file

PFB my shell script which reads a csv file to process it ############################################### fn_java(){ echo JAVA_TOP is $JAVA_TOP echo "cp $filename $filepath/$filename" cp $filename $filepath/$filename } #########################################... (9 Replies)
Discussion started by: Prasannag87
9 Replies

5. Shell Programming and Scripting

how to get data from hex file using SED or AWK based on pattern sign

I have a binary (hex) file I need to parse to get some data which are encoded this way: .* b4 . . . 01 12 .* af .* 83 L1 x1 x2 xL 84 L2 y1 y2 yL By another words there is a stream of hexadecimal bytes (in my example separated by space for better readability). I need to get value stored in... (3 Replies)
Discussion started by: sameucho
3 Replies

6. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

7. Shell Programming and Scripting

Type ¥ yen sign in a terminal or a file

I'm trying to enter ¥ yen sign which is a part of a complex password in terminal putty thru bash shell how can i type such character in terminal or even write it in a file as a stdin for the client thanks ---------- Post updated at 05:38 PM ---------- Previous update was at 02:07 PM... (0 Replies)
Discussion started by: h@foorsa.biz
0 Replies

8. Shell Programming and Scripting

Remove # sign from the file

Hello Friends, i need help to remove "#" sign from a file. I want to remove the "#" marks just in the area mentioned in red. I am not so good in awk, this help would be deeply appreciated. thanks Ado trap = { # { # trap-community = SNMP-trap # hosts = hubble,... (14 Replies)
Discussion started by: asirohi
14 Replies

9. Shell Programming and Scripting

Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem. I need... (1 Reply)
Discussion started by: Glider
1 Replies

10. HP-UX

Replace $ sign within a file using Vi editor

Can someone help me with this command? I want to replace amount fields which are in the format $99.99 to 99.99 in a large data file which is within a HP box. I use Vi editor and tried this command :1,$s//$///g And this does not seem to work Also, I want to replace ^M with spaces in the... (1 Reply)
Discussion started by: dtonse
1 Replies
Login or Register to Ask a Question