awk, sed, perl assistance in outputting formatted file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk, sed, perl assistance in outputting formatted file
# 1  
Old 11-27-2009
awk, sed, perl assistance in outputting formatted file

Hello,

Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers.


INPUT:
Code:
ACTASS=
802
BASECOS=
279
COSNCHG=
3
CUSCOS=
52
UPLDCOS=
2

DESIRED OUTPUT:
Code:
ACTASS=802
BASECOS=279
COSNCHG=3
CUSCOS=52
UPLDCOS=2

If solved can someone please direct in the correct route for a newbie scripter to find this answer. I am think search and then append bottom line to = sign.

Thank you to anyone that takes the time to explain. I have gained so much useful knowledge at this site.

Regards,
Abacus
# 2  
Old 11-27-2009
Code:
awk '{ORS=(/=/)?X:RS}1' file

Smilie
# 3  
Old 11-27-2009
[solved]

Holy Crap,
Amazing. I hate to ask you. However I have been studying awk and I will try to look this up. However can you please break this down.

I am thankful if you choose not too.

Thanks,

Abacus

PS: I am out of bits to award you. I will try however.

HEHE

SOLVED
# 4  
Old 11-27-2009
Quote:
Originally Posted by abacus
However I have been studying awk and I will try to look this up.
If you want to take the shortcut take a look at awk cheat sheet
What I did was just playing with ORS value, between RS and X(has no value, is NULL).

Success Smilie
# 5  
Old 11-27-2009
Code:
while read -r line
do
    case "$line" in
        *=)
            printf "%s" $line
            read d
            echo $d
            ;;
    esac
done <"file"

# 6  
Old 11-27-2009
Another one:
Code:
while read -r line
do
	case "$line" in 
		*=) printf "%s"   $line;;
		*)  printf "%s\n" $line;; 
	esac
done < file

# 7  
Old 11-27-2009
Code:
sed 'N;s/=\n/=/' infile

Code:
sed 'N;s/\n//' infile


Last edited by Scrutinizer; 11-27-2009 at 09:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing a formatted file with awk

Hi - I want to interrogate information about my poker hands, sessions are all recorded in a text file in a particular format. Each hand starts with the string <PokerStars> followed by a unique hand reference and other data like date/time. There is then all the information about each hand. My first... (5 Replies)
Discussion started by: rbeech23
5 Replies

2. Shell Programming and Scripting

awk operation to get table formatted file

I need to parse .conf file in Unix system to get output from the snippets like below : ; generated by mod_identity exten => int,1,GoSub(mdc_template-3,s,1) exten => int,n(next_380),Return() ; default action for busy exten => ext,1,GoSub(mdc_template-3,s,1) exten => ext,n,Set(PRI_CAUSE=17)... (2 Replies)
Discussion started by: cheecky
2 Replies

3. Shell Programming and Scripting

Modify the file with awk,sed or perl

Hi All, I need help from any of you.Would be so thankful for your help. I/P DDDD,1045,161,1557,429,1694,800,1911,1113,2460,1457,2917> 1609,3113,1869,3317,2732,3701,3727,4132,5857,5107> 9004,6496 DDDD,1125,157,1558,429,1694,800,1911,1117,2432,1444,2906>... (2 Replies)
Discussion started by: Indra2011
2 Replies

4. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

5. Shell Programming and Scripting

Using sed (or awk or perl) to delete rows in a file

I have a Unix file with 200,000 records, and need to remove all records from the file that have the character ‘I' in position 68 (68 bytes from the left). I have searched for similar problems and it appears that it would be possible with sed, awk or perl but I do not know enough about any of these... (7 Replies)
Discussion started by: joddo
7 Replies

6. Shell Programming and Scripting

reformatting xml file, sed or awk I think (possibly perl)

I have some xml files that cannot be read using a standard parser, or I am using the wrong parser. The issues seems to be spaces in some of the tags. Here is a sample,<UgUn 2 > <Un> -0.426753 </Un> </UgUn>The parser isn't able to find the number 2, so that information is lost, etc. It seems... (16 Replies)
Discussion started by: LMHmedchem
16 Replies

7. Shell Programming and Scripting

Script Assistance - Outputting to file with Awk

I'm trying to take a list of domains, find out the MX resolve it to IP then find out what the NS is and output the contents to a new file. The only problem i'm having is when checking the Ip or host of the MX i can only get it to print the column with the MX record and the results of the host... (1 Reply)
Discussion started by: spartan22
1 Replies

8. Programming

Perl GD::Graph and outputting to a graphics file

To successfully export a perl GD::Graph object to a graphics file (e.g. a .png file), do you do the following ? # Set graph data $graph->set(....); $graph->plot(\@graph_data); open(IMG,'>file.png') or die $!; binmode IMG; print IMG $graph->png; close IMG; Reason Im asking is... (1 Reply)
Discussion started by: JamesGoh
1 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

sed not outputting last line of input file

I am using sed for a simple substitution (see command syntax below). Everything works fine except that the last line of the input file does not get written to the output file. Has anyone ever seen this and know of way to force the last line to be written? I don't know if it's playing a part in... (3 Replies)
Discussion started by: 2reperry
3 Replies
Login or Register to Ask a Question