The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-22-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
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
  #2 (permalink)  
Old 12-22-2008
jatanig jatanig is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 10
Quote:
Originally Posted by thepurple View Post
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

open (FH,"<file");#where file contain your content
while(<FH>)
{
if (/\w+/)
{
print;
}
}
close (FH);
  #3 (permalink)  
Old 12-22-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
Quote:
Originally Posted by jatanig View Post
open (FH,"<file");#where file contain your
It will be better if I put the Filename rather the contents of the file. Any other way to put the filename??
  #4 (permalink)  
Old 12-22-2008
jatanig jatanig is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 10
Quote:
Originally Posted by thepurple View Post
It will be better if I put the Filename rather the contents of the file. Any other way to put the filename??
file - is the filename of the your file, in which ur required content is present.i.e

[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;
  #5 (permalink)  
Old 12-22-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Hi,

i am not sure if i understand what you want, but if
you only want to delete all empty lines, this should
do the trick:

sed '/^\s*$/d' file

HTH Chris
  #6 (permalink)  
Old 12-22-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
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??
  #7 (permalink)  
Old 12-22-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
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
Closed Thread

Bookmarks

Tags
awk, awk trim, shell script, shell scripting, trim, trim awk, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0