Remove Blank Rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove Blank Rows
# 8  
Old 12-07-2010
In your tr -d ' ' command, add the \r :

tr -d ' \r' you could even add \t if you also want to remove <tab> stuff :

tr -d ' \r\t'

Then rerun your script and let us know
# 9  
Old 12-07-2010
Here is what I got:

Code:
*
0632760          \r  \n   2   0   3   1   0   6   7   1   ,   7   3   0
0633000   7   ,   P   R   T   _   F   R   _   F   O   S   -   P   R   I
0633020   _   S   A   _   D   A   M   ,   D   0   0   2   0   2   0   0
0633040   0   0   6   ,   O   2   4   C   ,   P   R   T   _   F   R   _
0633060   F   O   S   ,   ,   P   R   I   _   S   A   _   D   A   M   ,
0633100   ,   .   1   ,   U   S   D   ,   7   3   0   7   ,   P   R   T
0633120   _   F   R   _   F   O   S   -   P   R   I   _   S   A   _   D
0633140   A   M   ,   D   0   0   2   0   2   0   0   0   0   6   ,   O
0633160   2   4   C   ,   P   R   T   _   F   R   _   F   O   S   ,   ,
0633200   P   R   I   _   S   A   _   D   A   M   ,   ,   .   1   ,   U
0633220   S   D   ,   1   3   ,   1   0   0   0   0   .   9   ,   0   ,
0633240   2   0   1   1   0   1   2   4
0633260
*
0634720                                                  \r  \n   2   0
0634740   3   1   4   0   1   9   ,   7   9   3   6   ,   P   R   T   _
0634760   I   T   _   V   C   E   -   P   R   I   _   S   A   _   D   A
0635000   M   ,   D   0   0   2   0   2   0   0   0   0   5   ,   O   2
0635020   4   C   ,   P   R   T   _   I   T   _   V   C   E   ,   ,   P
0635040   R   I   _   S   A   _   D   A   M   ,   ,   .   1   ,   U   S
0635060   D   ,   7   9   3   6   ,   P   R   T   _   I   T   _   V   C
0635100   E   -   P   R   I   _   S   A   _   D   A   M   ,   D   0   0

Does it mean it plugs-in an '*'? Also, what does \r \n denote? The last record only has that:

Code:
0641160
*
0642620                                          \r  \n      \n
0642636


Last edited by Scott; 12-07-2010 at 10:05 AM.. Reason: Code tags please
# 10  
Old 12-07-2010
This:
Code:
\r  \n

means carriage return / line feed (CRLF) , which is a Windows format. You need to convert the file to Unix format (LF).
# 11  
Old 12-07-2010
can u share some part of your input file with us?
R0H0N
# 12  
Old 12-07-2010
How do I code that? Here is the segment of my code where I unzip the file?

Code:
#Copy and uncompress the file

    cp -f ${SRCEFILE} ${TARGETFILE}

    resultcode=$?
    if [[ $resultcode != 0 ]]
    then
      echo "Error: Copying ${SRCEFILE} to ${TARGETFILE}"
      exit $resultcode
    else
      SourceFileSize=`wc ${SRCEFILE} | cut -d " " -f 3`
      TargetFileSize=`wc ${TARGETFILE} | cut -d " " -f 3`
      if [[ $SourceFileSize != $TargetFileSize ]]; then
        echo " File Copy failed "
        echo "Check the permission and Restart the Job"
        exit 1
      fi
     echo "File $SRCEFILE copied Successfully to ${TARGETFILE}"
     chmod 777 ${TARGETFILE}
     echo "File Permission modified "    
     gunzip -a ${TARGETFILE}

Moderator's Comments:
Mod Comment Use code tags, please...
# 13  
Old 12-07-2010
Normally gunzip -a would take care of that, but perhaps it is not supported on your platform? After the gunzip you need to do something like this:
Code:
tr -d '\r' < infile > outfile

where infile is the filename that remains after the gunzip
# 14  
Old 12-07-2010
So encoding that, it would look like this correct?
Code:
cp -f ${SRCEFILE} ${TARGETFILE}

    resultcode=$?
    if [[ $resultcode != 0 ]]
    then
      echo "Error: Copying ${SRCEFILE} to ${TARGETFILE}"
      exit $resultcode
    else
      SourceFileSize=`wc ${SRCEFILE} | cut -d " " -f 3`
      TargetFileSize=`wc ${TARGETFILE} | cut -d " " -f 3`
      if [[ $SourceFileSize != $TargetFileSize ]]; then
        echo " File Copy failed "
        echo "Check the permission and Restart the Job"
        exit 1
      fi
     echo "File $SRCEFILE copied Successfully to ${TARGETFILE}"
     chmod 777 ${TARGETFILE}
     echo "File Permission modified " 
     tr -d '\r' ${TARGETFILE}   
     gunzip -a ${TARGETFILE}   


Last edited by Scott; 12-07-2010 at 11:02 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting columns of text to rows, with blank lines

I've spent the past hour trying different things and googling for this solution and cannot find the answer. Found variations of this, but not this exact thing. I have the following text, which is the output from our mainframe. Each field is on a separate line, with a blank line between each... (7 Replies)
Discussion started by: lupin..the..3rd
7 Replies

2. Shell Programming and Scripting

Need to remove a selection of rows separated by blank lines

hello, here is an example: 9.07 9.05 0.00 2.28 0.00 0.08 1.93 3.62 10.97 12.03 12.03 0.00 2.73 0.00 0.07 (3 Replies)
Discussion started by: Baron1
3 Replies

3. Shell Programming and Scripting

Perl : blank lines are displayed in the output after deleting few rows from excel

I am working on an assignment to pull all the records from excel sheet programatically and use the data for further calculations. In this process, I first defined 10 records in excel sheet and executed the below code. In the first run it is OK. But after deleting last few rows in excel sheet and... (0 Replies)
Discussion started by: giridhar276
0 Replies

4. Shell Programming and Scripting

Copying down first row in to all the below blank rows in a .csv file

Hi All, I have many of files(.csv) of the format given below. Date,Name,Location 04/02/2012,A,India ,B,China ,C,USA Like this I have 1000's of rows and many columns in all my files. I need a shell script to copy down the Date(in this example column1) to the next 2 rows below(in the... (8 Replies)
Discussion started by: ks_reddy
8 Replies

5. Shell Programming and Scripting

How to remove blank lines

Hi, I am facing a problem related to removing blank lines from a text document. Input Error 17-05-2011 11:01:15 VisualSVN Server 2.1 1001 The following information was included with the event: line3 line4 Error 17-05-2011 11:00:25 VisualSVN Server 2.1 ... (13 Replies)
Discussion started by: mayursingru
13 Replies

6. Shell Programming and Scripting

How to remove Blank rows in a csv file

Hi, I need help to remove blank rows at the end of file. Sample data: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 "Tønsberg, Brygga Kino SF",Tønsberg,202-1,Tønsberg SF 4,202-1-4 ,,,, ,,,, ,,,, ,,,, Expected data: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 "Tønsberg, Brygga... (6 Replies)
Discussion started by: cnraja
6 Replies

7. Shell Programming and Scripting

Remove 1st two rows and last 2 rows

Hi All, I need to remove 1st 2 line from head and last 2 line from last. I thought it would be possible by using the Head and tail command. But after i am using it is not possible by it. Example:Input file 1 2 3 4 5 Example: Output file 3 But my head and tail command are not... (12 Replies)
Discussion started by: kam786sim
12 Replies

8. Shell Programming and Scripting

how to delete blank rows in a log file

Help How to delete all blank rows in log file (4 Replies)
Discussion started by: suryanarayana
4 Replies

9. UNIX for Dummies Questions & Answers

Remove blank lines

¿How can i remove blank lines between all lines in a long text file? Example WrongFile.txt : Line 1 Line 2 Line 3 CorrectFile.txt : Line 1 Line 2 Line 3 Thanks in advance :confused: (4 Replies)
Discussion started by: osymad
4 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question