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
  #8 (permalink)  
Old 12-22-2008
jatanig jatanig is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 10
Thumbs up

Quote:
Originally Posted by thepurple View Post
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??
That Script what I told u is PERL script.and FH is file handler there.
if u want to use shell script then do

In shell script
#!/bin/sh

SCRIPT_DIR/run_cmd_.sh 192.131.58.35 uname pass $line | grep -v "Enter command:" >> REPORT_DIR/file.TMP
sed '/^\s*$/d' /home/rahul/jatin/REPORT_DIR/file.TMP > REPORT_DIR/file.LOG
  #9 (permalink)  
Old 12-22-2008
reddyrajal reddyrajal is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 24
grep -v ^$ file
  #10 (permalink)  
Old 12-22-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
I am really wondered why none of the below is not working for my file!!!! It does not clear the empty lines & join.
grep -v ^$ filename

sed '/^\s*$/d' filename
  #11 (permalink)  
Old 12-22-2008
reddyrajal reddyrajal is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 24
if u copy file from windos try this command

dos2unix filename
grep -v ^$ filename
here is my output
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;
  #12 (permalink)  
Old 12-22-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
Okay i think I found why its not working. I did dos2unix filename. But still no outcome. Later i check the file with VI. I found-

DELETE:MD:TM,432350214576013;^M
^M
RESP:940120105;^M
DELETE:MD:TM,432350415547447;^M
^M
RESP:940120105;^M
SET:NOK:TM,432350110811018:T22,0;
^M
RESP:11000999;^M

^M is creating problem !!! please make your suggestion
  #13 (permalink)  
Old 12-22-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Code:
sed '/^\s*^M/d file
Press Ctrl-v followed by Ctrl-m to enter "^M".
  #14 (permalink)  
Old 12-22-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Code:
sed '/^\s*^M/d' file
Press Ctrl-v followed by Ctrl-m to enter "^M".
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:45 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