![]() |
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 |
| replacing multiple lines with single line | siba.s.nayak | Shell Programming and Scripting | 3 | 05-28-2008 02:43 AM |
| Reading Multiple Variables From a Single Line in Shell | Drek | Shell Programming and Scripting | 14 | 12-21-2006 11:20 AM |
| reading a single line | rochitsharma | Shell Programming and Scripting | 2 | 02-27-2006 01:06 AM |
| Splitting a single line into multiple lines | thanuman | Shell Programming and Scripting | 4 | 02-23-2005 04:56 AM |
| reading a single character in C | alodha | High Level Programming | 3 | 01-28-2005 06:22 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Reading multiple lines as single
Hi,
Is it possible to read every 2 lines as single record, I have a file like below, Code:
~CZK ~TSCHECHISCHE KRONE ~TSCHECH. REPUBLIK
Dec 1 2005 12:00AM~ 10.840000~
~DKK ~DAENISCHE KRONE ~DAENEMARK
Dec 2 2005 12:00AM~ 17.451000~
~DZD ~ALGERISCHER DINAR ~ALGERIEN
Dec 3 2005 12:00AM~ 16.100000~
~EEK ~ESTNISCHE KRONE ~ESTLAND
~CZ~TSCHECHISCHE KRONE~TSCHECH. REPUBLIK~Dec 1 200512:00AM ~10.840000~ i.e something the does the opposite of fold. Is this possible to do in awk or ???? Thanks a lot Last edited by braindrain; 10-17-2006 at 12:01 PM.. |
|
||||
|
I'm sure someone will be able to get your desired output into a single field, but here it is in two:
Code:
awk 'BEGIN { RS = "/^~/" ; FS = "\n" ; OFS = "~" } {gsub(/ +/, "") ; print $1,$2 }'
Last edited by petebear; 10-17-2006 at 11:57 AM.. |
|
||||
|
If you have Python:
Code:
#!/usr/bin/python
data = open("file.txt").readlines()
for i in range(len(data)):
try:
if data[i].startswith("~"):
data[i] = data[i].strip() #strip new lines
s = data[i] + "~" + data[i+1] #concat 2 lines
print s.replace(" ","").strip() #replace all spaces and strip new lines
except:
print data[i].replace(" ","") + "~"
Code:
~CZK~TSCHECHISCHEKRONE~TSCHECH.REPUBLIK~Dec1200512:00AM~10.840000~ ~DKK~DAENISCHEKRONE~DAENEMARK~Dec2200512:00AM~17.451000~ ~DZD~ALGERISCHERDINAR~ALGERIEN~Dec3200512:00AM~16.100000~ ~EEK~ESTNISCHEKRONE~ESTLAND~ |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|