form a line with strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting form a line with strings
# 1  
Old 10-31-2008
Java form a line with strings

hi i have a file with the content like

TL1330000000800
000DE9147157200
08000TS0228DE91
71572AMEX0000.T
N
0080000000
00000.


TL1330000000500
000DE9147157200
08000TS0228DE91
71572AMEX0000.T
N
0080000000
00000.
i need to write like including the spaces
TL1330000000800000DE914715720008000TS0228DE9171572AMEX0000.TN 008000000000000.
TL1330000000500000DE914715720008000TS0228DE9171572AMEX0000.TN 008000000000000.

please help its urgent

thanks
Satya
# 2  
Old 10-31-2008
this may do what you require, depends if there is a space after the N or not, I cannot tell as you didn't use code tags around your data.
Code:
{
# is this a blank line
    /^$/!{
# not a blank line
# append it to the hold space
        H
# remove it from the pattern space
            d
    }
    /^$/{
# this is a blank line
# swap it with the hold space
        x
# delete the newline chars in the pattern space
            s/\n//g
# print the pattern space
            p
    }
# is this still a blank line
# delete it if so
    /^$/d
}

save that into a file (callled script.sed below, call it what you like) and call it thus:
Code:
sed -f script.sed data.file >output.file

# 3  
Old 10-31-2008
following should work:

Code:
#  sed -n '/^TL/{N;N;N;N;s/\n//g;N;s/\n/ /g;N;s/\n//g;p;}' infile

# 4  
Old 10-31-2008
With AWK (nawk or /usr/xpg4/bin/awk on Solaris):

Code:
awk '$(NF-2)=$(NF-2)FS' OFS= RS= infile

# 5  
Old 10-31-2008
Hammer & Screwdriver One more approach

I had to force a space after that "N" all alone on a line (from input), as it did not appear to be there, but was requested for output.

Code:
> cat file23
TL1330000000800
000DE9147157200
08000TS0228DE91
71572AMEX0000.T
N
0080000000
00000.


TL1330000000500
000DE9147157200
08000TS0228DE91
71572AMEX0000.T
N
0080000000
00000.

> cat file23 | sed "s/\.$/\.~/" | sed "s/^N$/N /" | tr -d "\n" | tr "~" "\n"
TL1330000000800000DE914715720008000TS0228DE9171572AMEX0000.TN 008000000000000.
TL1330000000500000DE914715720008000TS0228DE9171572AMEX0000.TN 008000000000000.
>

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. UNIX for Dummies Questions & Answers

How to submit form on an php webpage from command line?

Hello, i have page domain.com/form.php the form fields on form.php are named: name=ipaddress name=port and submit button is named: submit i want to ask how the linux command will look like to submit the form filled with: ipaddress: 127.0.0.1 port: 80 I tried various curl and... (5 Replies)
Discussion started by: postcd
5 Replies

3. Shell Programming and Scripting

Comparing two strings receiving form two different loops and execute if condition when single match

I want to read a file contain sub-string and same string need to match in file name I got from for loop. I am using below code: #!/bin/bash C_UPLOADEDSUFFIX='.uploaded' files=$(find . -iname '*'$C_UPLOADEDSUFFIX -type f) # find files having .uploaded prefix for file in $files do ... (1 Reply)
Discussion started by: ketanraut
1 Replies

4. Shell Programming and Scripting

How to remove the # char form a line?

Hi, my file has below details and I want remove the # char from only specific line. #TEST:00:START #TEST1:01:INPROCESS #TEST2:02:ABOUTTO #TEST3:03:COMP i.e if want remove the # from 2nd line then file to be updated as #TEST:00:START TEST1:01:INPROCESS #TEST2:02:ABOUTTO... (6 Replies)
Discussion started by: sandyrajh
6 Replies

5. Shell Programming and Scripting

how to form Records[multiple line] between two known patterns

file contents looks like this : #START line1 of record1 line2 of record1 #END #START line1 of record2 line2 of record2 line3 of record2 #END #START line1 of record3 #END my question how should i make it a records between #START and #END . willl i be able to get the contents of the... (5 Replies)
Discussion started by: sathish92
5 Replies

6. Shell Programming and Scripting

How to read one character form each line of the file?

Hi, Maybe this iscorrect forum for my question... I should read one character at a fixed position from each line of the file. So how ??? should be substituted in the code below: while read line ; do single_char=`???` echo "$single_char" done < $input_file OK...I did get an... (0 Replies)
Discussion started by: arsii
0 Replies

7. Shell Programming and Scripting

Get line form file by line number

I want to get a specific line form file by line number. For example I have file named bla File looks like this cat bla Madrid Paris Berlin Vladivostok I want to put line 3 (Berlin) into variable X. How to do that? (3 Replies)
Discussion started by: corny
3 Replies

8. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies
Login or Register to Ask a Question