![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to join lines | glamo_2312 | UNIX for Dummies Questions & Answers | 8 | 09-16-2008 04:17 AM |
| trim lines | melanie_pfefer | Shell Programming and Scripting | 6 | 03-26-2008 07:25 AM |
| How to count lines - ignoring blank lines and commented lines | kthatch | UNIX for Dummies Questions & Answers | 6 | 05-25-2007 01:21 AM |
| delete blank lines or lines with spaces only | vascobrito | UNIX for Dummies Questions & Answers | 3 | 01-13-2004 07:36 AM |
| join two lines together | tine | Shell Programming and Scripting | 4 | 12-12-2003 12:34 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Trim blank lines and Join toghether
Hi Experts,
Is there any script that will trim the blank linkes from the below files and join the lines--? DELETE:MD:TM,432350214576013; RESP:940120105; DELETE:MD:TM,432350415547447; RESP:940120105; SET:NOK:TM,432350110811018:T22,0; RESP:11000999; SET:MD:TM,4323500223734641; RESP:0; SET:NOK:TM,432350220813251:BAIC,1; RESP:0; SET:MD:TM,4323502142003351; RESP:0; DELETE:MD:TM,432350415283715; RESP:0; DELETE:MD:TM,432350415434001; RESP:0; SET:MD:TRIM,989370025055:LANG,English; RESP:0; DELETE:MD:TM,432350041977269:TRIM,989371036084;; RESP:940120105; SET:MD:TM,432350214483040; RESP:0; DELETE:MD:TM,432350021443483:TRIM,989362585071; RESP:0; OUTPUT Should be- DELETE:MD:TM,432350214576013; RESP:940120105; DELETE:MD:TM,432350415547447; RESP:940120105; SET:NOK:TM,432350110811018:T22,0; RESP:11000999; SET:MD:TM,4323500223734641; RESP:0; SET:NOK:TM,432350220813251:BAIC,1; RESP:0; SET:MD:TM,4323502142003351; RESP:0; DELETE:MD:TM,432350415283715; RESP:0; DELETE:MD:TM,432350415434001; RESP:0; SET:MD:TRIM,989370025055:LANG,English; RESP:0; DELETE:MD:TM,432350041977269:TRIM,989371036084;; RESP:940120105; SET:MD:TM,432350214483040; RESP:0; DELETE:MD:TM,432350021443483:TRIM,989362585071; RESP:0; //Purple |
|
||||
|
Quote:
open (FH,"<file");#where file contain your content while(<FH>) { if (/\w+/) { print; } } close (FH); |
|
||||
|
Quote:
[jatin]$ cat file DELETE:MD:TM,432350214576013; RESP:940120105; DELETE:MD:TM,432350415547447; RESP:940120105; SET:NOK:TM,432350110811018:T22,0; RESP:11000999; SET:MD:TM,4323500223734641; RESP:0; SET:NOK:TM,432350220813251:BAIC,1; RESP:0; SET:MD:TM,4323502142003351; RESP:0; DELETE:MD:TM,432350415283715; RESP:0; DELETE:MD:TM,432350415434001; RESP:0; SET:MD:TRIM,989370025055:LANG,English; RESP:0; DELETE:MD:TM,432350041977269:TRIM,989371036084;; RESP:940120105; SET:MD:TM,432350214483040; RESP:0; DELETE:MD:TM,432350021443483:TRIM,989362585071; RESP:0; |
|
||||
|
Okay thats fine.
I have script which actually make the file content like above. Now i want to trim and join the blank lines- Below is the total script will be look like. Please help me to correct the script- #!/usr/bin/bash $SCRIPT_DIR/run_cmd_.sh 192.131.58.35 uname pass $line | grep -v "Enter command:" >> $REPORT_DIR/$file.TMP #$file.tmp will contail untrim and unjoined lines #to trim and join the lines open (FH,"<$REPORT_DIR/$file.TMP"); while(<FH>) { if (/\w+/) { print; } } close (FH); mv $REPORT_DIR/$file.TMP $REPORT_DIR/$file.LOG By the way, what is "FH" here?? |
|
||||
|
hi christoph, you are right.. i want to delte all empty lines and join. i tried yours
"sed '/^\s*$/d' filename". But not working. Output did not delete the empty lines. ![]() |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, shell script, shell scripting, trim, trim awk, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|