Lines Concatenated with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Lines Concatenated with awk
# 1  
Old 01-12-2009
Lines Concatenated with awk

Hello,

I have a bash shell script and I use awk to print certain columns of one file and direct the output to another file. If I do a less or cat on the file it looks correct, but if I email the file and open it with Outlook the lines outputted by awk are concatenated.

Here is my awk line:
awk '{print $6" "$7" "$8" "$9" "$5}' /data/tmp/snapshots_report.deltas >> $EMAIL_BODY

I use a perl script to email it.

Here is how it looks with cat:
[root@rmhesx01 tmp]# cat snapshots_report.email
Adam1:
Jan 12 11:19 Adam1-000001-delta.vmdk 7.0K
Jan 12 11:19 Adam1-000002-delta.vmdk 7.0K
Jan 12 11:19 Adam1-000003-delta.vmdk 16M
Jan 12 11:19 Adam1_1-000001-delta.vmdk 10K
Jan 12 11:19 Adam1_1-000002-delta.vmdk 10K
Jan 12 11:19 Adam1_1-000003-delta.vmdk 10K

Centramax:
Jan 12 11:19 Centramax-000001-delta.vmdk 16M

Looks like this in my email client:

Adam1:
Jan 12 11:19 Adam1-000001-delta.vmdk 7.0K Jan 12 11:19 Adam1-000002-delta.vmdk 7.0K Jan 12 11:19 Adam1-000003-delta.vmdk 16M Jan 12 11:19 Adam1_1-000001-delta.vmdk 10K Jan 12 11:19 Adam1_1-000002-delta.vmdk 10K Jan 12 11:19 Adam1_1-000003-delta.vmdk 10K

Centramax:
Jan 12 11:19 Centramax-000001-delta.vmdk 16M

I know that linux uses LF for newline and windows uses CRLF, but I cant figure out if that is what is causing this issue. I have tried adding "\n" to my awk statement but then I get double-spacing which I dont want.

Any ideas?
# 2  
Old 01-12-2009
You can add a CR with your awk command like this:

Code:
awk '{print $6" "$7" "$8" "$9" "$5 "\015"}'

Regards
# 3  
Old 01-12-2009
Hammer & Screwdriver dos2unix and unix2dos

You might want to investigate dos2unix and unix2dos. These two commands help convert files to adjust for the differences in file structures.
I know that I use these frequently to handle CR (carriage return) and LF (line feed) issues.
# 4  
Old 01-12-2009
Quote:
Originally Posted by Franklin52
You can add a CR with your awk command like this:

Code:
awk '{print $6" "$7" "$8" "$9" "$5 "\015"}'

Regards
Just tried that and the output looks exactly the same.

I have also tried unix2dos with no success.

Here is my full script:
#!/bin/bash
#
# Written by Adam Stahl on 1/9/09
#
# This script emails a report of VMs having snapshots.

PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
SCRIPT_NAME=$0
HOSTNAME=`hostname | awk -F. '{print $1}' | tr '[a-z]' '[A-Z]'`
EMAIL_BODY=/data/tmp/snapshots_report.email
FLAG=0

> $EMAIL_BODY

# Loop through all VMs running on the host
for VM_CONFIG in `vmware-cmd -l`
do
# Get the VMs name
VM_NAME=`basename $VM_CONFIG | awk -F. '{print $1}'`
# Get the VMs directory
VM_DIR=`dirname $VM_CONFIG`

# Go into the directory and look for snapshot files
cd $VM_DIR
ls -lah *delta* > /dev/null 2>&1
if [ $? -eq 0 ]; then
ls -lah *delta* > /data/tmp/snapshots_report.deltas
echo $VM_NAME: >> $EMAIL_BODY
awk '{print $6" "$7" "$8" "$9" "$5"\n"}' /data/tmp/snapshots_report.deltas >> $EMAIL_BODY
# echo >> $EMAIL_BODY
FLAG=1
fi
done

if [ $FLAG -eq 0 ]; then
echo "No snapshots exist" > $EMAIL_BODY
fi

# Send the email
/data/scripts/sendmail.pl claven.rhsnet.org $HOSTNAME@rhsnet.org astahl@rhsnet.org "$HOSTNAME: Weekly Snapshot Report" $EMAIL_BODY
# 5  
Old 01-12-2009
Hammer & Screwdriver can we see the EMAIL_BODY file?

best --

Code:
>cat $EMAIL_BODY | od -An -t dC -w10

which will show the file as created. Very interested to see if there are '10' characters and/or '13' characters, which are line-feed and carriage-return.

Could that perl script that is emailing also be involved in this oddity? Have you tried mailx or mutt for email?
# 6  
Old 01-13-2009
Quote:
Originally Posted by joeyg
best --

Code:
>cat $EMAIL_BODY | od -An -t dC -w10

which will show the file as created. Very interested to see if there are '10' characters and/or '13' characters, which are line-feed and carriage-return.

Could that perl script that is emailing also be involved in this oddity? Have you tried mailx or mutt for email?
Well here is the output of the command you gave me:

[root@rmhesx01 scripts]# cat adam2 | od -An -t dC -w10
86 77 95 78 65 77 69 58 10 32
32 32 32 32 32 10 74 97 110 32
49 51 32 49 48 58 53 52 32 32
46 32 32 52 46 48 75 10 74 97
110 32 57 32 49 49 58 50 48 32
32 46 46 32 32 52 46 48 75 10
65 112 114 32 50 57 32 50 48 48
56 32 32 97 99 116 105 118 101 95
110 105 99 95 99 104 101 99 107 46
115 104 32 32 49 46 49 75 10 74
97 110 32 49 51 32 49 48 58 53
52 32 32 97 100 97 109 49 32 32
48 10 65 112 114 32 50 56 32 50
48 48 56 32 32 115 101 110 100 109
97 105 108 46 112 108 32 32 54 52
54 10 74 97 110 32 49 50 32 48
56 58 52 55 32 32 115 110 97 112
115 104 111 116 115 95 114 101 112 111
114 116 46 115 104 32 32 49 46 48
75 10 74 97 110 32 57 32 49 54
58 51 57 32 32 115 110 97 112 115
104 111 116 115 95 114 101 112 111 114
116 46 115 104 46 98 97 107 32 32
49 46 49 75 10

I am not sure how to interpret that.
# 7  
Old 01-14-2009
I got it working. Using "printf" instead of "print" did the trick.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

2. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

3. Shell Programming and Scripting

Look up 2 files and print the concatenated output

file 1 Sun Mar 17 00:01:33 2013 submit , Name="1234" Sun Mar 17 00:01:33 2013 submit , Name="1344" Sun Mar 17 00:01:33 2013 submit , Name="1124" .. .. .. .. Sun Mar 17 00:01:33 2013 submit , Name="8901" file 2 Sun Mar 17 00:02:47 2013 1234 execute SUCCEEDED Sun Mar 17... (24 Replies)
Discussion started by: aravindj80
24 Replies

4. Shell Programming and Scripting

Print only lines where fields concatenated match strings

Hello everyone, Maybe somebody could help me with an awk script. I have this input (field separator is comma ","): 547894982,M|N|J,U|Q|P,98,101,0,1,1 234900027,M|N|J,U|Q|P,98,101,0,1,1 234900023,M|N|J,U|Q|P,98,54,3,1,1 234900028,M|H|J,S|Q|P,98,101,0,1,1 234900030,M|N|J,U|F|P,98,101,0,1,1... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

5. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

6. Shell Programming and Scripting

[Bash/Makefile] Concatenated string of filenames?

How would I go about storing a list of files in a sub-directory into a variable for argument passing? (2 Replies)
Discussion started by: ChazZeromus
2 Replies

7. Solaris

Need to attach one slice with existing concatenated volume

Hi I need to add new slice to existing concatenated volume. Please let me know the process to do the same I have d0 concatenated volume which consist of c1t0d0s7 & c1t2d0s0 bash-3.00# df -h /export/home Filesystem size used avail capacity Mounted on /dev/md/dsk/d0 ... (3 Replies)
Discussion started by: sb200
3 Replies

8. UNIX for Dummies Questions & Answers

Getting non unique lines from concatenated files

Hi All, Is there a way to get NON unique lines from 2 or more concatenated files? Basically I have several files which are very similar with the exception of few lines and I want to find out which lines are different in each file. Very simple example is file1 contains: 1 2 3 4 5file2... (122 Replies)
Discussion started by: pawannoel
122 Replies

9. Shell Programming and Scripting

Splitting Concatenated Words With Largest Strings First

hello, I had posted earlier help for a script for splitting concatenated words . The script was supposed to read words from a master file and split concatenated words in the slave/input file. Thanks to the help I got, the following script which works very well was posted. It detects residues by... (14 Replies)
Discussion started by: gimley
14 Replies

10. Solaris

Disksuite Raid 0 Concatenated Volume - booting from cdrom

Hello, If I boot up from install media in single user mode (Solaris 9 - if it matters), will I be able to mount a concatenated volume? I have combined several disks into one non-os filesystem and I want to be able to mount it while booted in single user mode from cdrom. i.e., mount... (0 Replies)
Discussion started by: calmgreen
0 Replies
Login or Register to Ask a Question