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
Strange Characters After Using Notepad dgower2 Shell Programming and Scripting 4 05-21-2009 12:01 PM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-25-2007 02:21 AM
Find lines greater than 80 characters in a file mrgubbala Shell Programming and Scripting 8 03-11-2007 12:51 AM
Split a huge line into multiple 120 characters lines with sed? jerome_1664 Shell Programming and Scripting 2 08-17-2006 01:03 PM
Strange Characters in Filename kristy UNIX for Dummies Questions & Answers 4 03-07-2002 06:38 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-28-2008
luiscarvalheiro luiscarvalheiro is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 6
Question Lines with strange characters and sed...

Dear All:

I Have a bunch of files which I'd like to process with a shell script. The problem is that the files have strange characters in their headers, like

�g�8@L-000-MSG2__-ABCD________-FIRA_____-000001___-200806181330-__
��e�
Data from BLABLABLA, Instrument: BLABLA, Date: 2008/06/18 13:30Z
Row: 1078 Col: 1130 Lat: -22.267 Lon: 22.256 *** Something here ***

For my intents, I only need the information (in this case) from line 3 onwards. Sometimes this strange header occupies 2 lines, others 3...others...I don't know.

I made a very simple test, like

FILE=`find . -type f -name "FILENAME"`

for i in $FILE
do

FNOW=`echo $i`

#Cuts two first lines of the file
sed '1,2d' $FNOW > newfile
sed '/^$/d' -i newfile

HEADER=`head -1 newfile | cut -c1-4`
if [ "$HEADER" != "Data" ]
then
sed '1d' -i newfile
sed '/^$/d' -i newfile
fi

#A simple testing
HEADER2=`head -1 newfile | cut -c1-4`
echo ${HEADER2},${HEADER} >> test.txt

done



The problem is that.....sometimes i don't get to cut all the "strange" headers to obtain "clean" files, as you can see in some lines of test.txt

Data,@H
Data,ۘ
Data,Data
Data,@H

(etc)

So:
Is there any way to fulfill my intentions with sed? Maybe some "delete all the first lines until find the expression «Data»? Honestly, i don't know what else to try.

Thank you very much in advance
 

Bookmarks

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 01:40 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