Can this be made into one single line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can this be made into one single line?
# 1  
Old 09-19-2002
Can this be made into one single line?

Can someone please suggest a script to make the following into one single (continuous) line so that a pattern search can be carried out on the resulting single line.

Note : Sample (may be shorter or longer) and will be contained in a text file

mstnpkpqrktkrntnrrpqdvkfpgggqivggvyllprrgprlgvrapr
rrqpipkarrpegrtwaqpgypwplygneglgwagwllsprgsrpswgpt
kvidtltcgfadlmgyiplvgaplggaaralahgvrvledgvnyatgnlp
llsclttpasayevhnvsgiyhvtndcsnasivyeaadlimhtpgcvpcv
altptlaarnvtiptttirrhvdllvgaaafcsamyvgdlcgsvflvsql
lqdcncsiypghvsghrmawdmmmnwspttalvvsqllripqavvdmvag
yysmagnwakvlivmllfagvdgdthvtggaqakttnrlvsmfasgpsqk
hinrtalncndslqtgflaalfythsfnssgcpermaqcrtidkfdqgwg
dqrpycwhypppqctivpasevcgpvycftpspvvvgttdrfgvptyrwg
ntrppqgnwfgctwmnstgftktcggppcniggvgnntltcptdcfrkhp
pwltprcmvdypyrlwhypctvnftifkvrmyvggvehrlnaacnwtrge
elsplllsttewqvlpcsfttlpalstglihlhqnivdvqylygigsavv
llfllladarvcaclwmmlliaqaeaalenlvvlnsasvagahgilsflv
rlvpgatyalygvwpllllllalpprayamdremaascggavfvglvllt
rliwwlqyfttraeadlhvwipplnarggrdaiillmcavhpelifditk
vlqagitrvpyfvraqglihacmlvrkvagghyvqmafmklgaltgtyiy
raglrdlavavepvvfsdmetkiitwgadtaacgdiilglpvsarrgkei
rglrllapitaysqqtrgllgciitsltgrdknqvegevqvvstatqsfl
vyhgagsktlaapkgpitqmytnvdqdlvgwpkppgarsltpctcgssdl
pvrrrgdsrgsllsprpvsylkgssggpllcpfghavgifraavctrgva
mettmrspvftdnssppavpqsfqvahlhaptgsgkstkvpaayaaqgyk
tlgfgaymskahgidpnirtgvrtittgapvtystygkfladggcsggay
tdsttilgigtvldqaetagarlvvlatatppgsvtvphpnieevalsnt
pieairggrhlifchskkkcdelaaklsglginavayyrgldvsviptig
mtgytgdfdsvidcntcvtqtvdfsldptftietttvpqdavsrsqrrgr
fvtpgerpsgmfdssvlcecydagcawyeltpaetsvrlraylntpglpv
vftglthidahflsqtkqagdnfpylvayqatvcaraqapppswdqmwkc
ptpllyrlgavqnevtlthpitkyimacmsadlevvtstwvlvggvlaal
vivgriilsgrpaivpdrellyqefdemeecashlpyieqgmqlaeqfkq
kqaeaaapvveskwraletfwakhmwnfisgiqylaglstlpgnpaiasl
lttqstllfnilggwvaaqlappsaasafvgagiagaavgsiglgkvlvd
galvafkvmsgempstedlvnllpailspgalvvgvvcaailrrhvgpge
afasrgnhvspthyvpesdaaarvtqilssltitqllkrlhqwinedcst
wdwictvltdfktwlqskllpqlpgvpffscqrgykgvwrgdgimqttcp
ngsmrivgpktcsntwhgtfpinayttgpctpspapnysralwrvaaeey
yvtgmttdnvkcpcqvpapeffsevdgvrlhryapacrpllreevtfqvg
pcepepdvavltsmltdpshitaetakrrlargsppslasssasqlsaps
spdadlieanllwrqemggnitrvesenkvvvldsfdplraeederevsv
fpaampiwarpdynpplleswkdpdyvppvvhgcplppikappippprrk
ssalaelatktfgssessavdsgtatalpdqasddgdkgsdvesyssmpp
sdgswstvseeasedvvccsmsytwtgalitpcaaeesklpinalsnsll
srsaglrqkkvtfdrlqvlddhyrdvlkemkakastvkakllsveeackl
gygakdvrnlsskavnhihsvwkdlledtvtpidttimaknevfcvqpek
fpdlgvrvcekmalydvvstlpqvvmgssygfqyspgqrveflvntwksk
rcfdstvtendirveesiyqccdlapearqaikslterlyiggpltnskg
sgvlttscgntltcylkasaacraaklqdctmlvngddlvvicesagtqe
amtrysappgdppqpeydlelitscssnvsvahdasgkrvyyltrdpttp
htpvnswlgniimyaptlwarmilmthffsillaqeqlekaldcqiygac
iierlhglsafslhsyspgeinrvasclrklgvpplrvwrhrarsvrarl
gkylfnwavktklkltpipaasrldlsgwfvagysggdiyhslsrarprw
gvgiyllpnr
# 2  
Old 09-19-2002
cat test.txt |tr -d "\n" > out.txt

should do the trick..

test.txt is the file with the data that you need to remove linefeed from..

out.txt will contain the same file without linefeed..

hope this helps!

/Peter C
# 3  
Old 09-19-2002
if the file has it in multiple lines shouldnt it stay in multiple lines. otherwise you would be tampering with the data.

if you notice the script i posted to do the search you are looking for it takes a file with multiple lines and does the search.

my perl script would have spit out the following for the data you have above.'

Code:
+=================================+
|COOL STUFF BY OPTIMUSP at UNIXCOM|
+=================================+
Line Position Found/Text
==== ======== ==========
20     8      1
              pvRRRGDSrgsllsprpvsylkgssggpllcpfghavgifraavctrgva

+-----------------------------+
49     45     1
              iierlhglsafslhsyspgeinrvasclrklgvpplrvwRHRARSvrarl

+-----------------------------+

# 4  
Old 09-20-2002
some number and then join...

You're going to hate yourselves when you see my answer.

If you can vi the file just use the "join" function with the number of lines. Like this.

N J


Where N is the number of lines and "J" is the Join function in vi.

If you want join 100 lines then:

100 J

Make sure you are in command mode!!!

Enjoy!!

Smilie Smilie
# 5  
Old 09-20-2002
Like Optimus_P, I don't understand why the OP is ignoring my solution to his problem. For the record, when the above input data is run against my script, it outputs:
Code:
Line: 20 At position 1 2 unmatched characters
Line: 20 At position 3 MATCH: rrrgds
Line: 20 At position 9 43 trailing characters
pvRRRGDSrgsllsprpvsylkgssggpllcpfghavgifraavctrgva


Line: 49 At position 1 39 unmatched characters
Line: 49 At position 40 MATCH: rhrars
Line: 49 At position 46 6 trailing characters
iierlhglsafslhsyspgeinrvasclrklgvpplrvwRHRARSvrarl

I then joined all of the lines together into one superline. And I commented out the 'echo "$image"' in my script so that it won't print out the line with matches upshifted. When the superline is run against my script, it outputs:
Code:
Line: 1 At position 1 952 unmatched characters
Line: 1 At position 953 MATCH: rrrgds
Line: 1 At position 959 289 unmatched characters
Line: 1 At position 1248 MATCH: rgrfvt
Line: 1 At position 1254 1186 unmatched characters
Line: 1 At position 2440 MATCH: rhrars
Line: 1 At position 2446 65 trailing characters

So I got one more match. This explains the motivation for trying to join the lines. I think a better solution is to modify the scripts to find matches across line boundaries. Eliminating the line boundaries is hard and neither of the solutions posted worked very well.

The data file has 2510 letters. That exceeds the maximum line that vi can handle, at least on HP-UX. So vi didn't work. As for the tr solution, I tried:
tr -s "\n" < file1 > file2
which kinda worked, but it left the file with no newline characters at all. Thus the file had zero lines. I used:
echo >> file2
to correct this problem.

At this point, my script worked and spit out the above results, but at some point, ksh will balk at reading a giant line. That's why switching to an algorithm that can match across line boundaries would be the better approach.
# 6  
Old 09-20-2002
Hammer & Screwdriver

Yes so far all suggestions are correct but let's clarify some points.

Making the mulitple lines into a single line does NOT tamper with the data as in fact it is ONE continuous line and is presented on the Protein description web pages as multiple lines for ease of display.

The problem comes in doing matches across line boundaries if the data isn NOT presented in one single line to the ksh script.

If we have a solution to make the searches possible across line boundaries then we have a winner.

My wife and I are carrying out tests with the ksh script and we came up with protein sequences that have many lines some times as many as 50.

So either we try to solve the ksh script, or PERL or we have to try amongst our C gurus which is why I posted there as well.

Someone appeared to be annoyed about my posting under C.

To clarify we aren't doing homework and this is an essential part of an advanced breast cancer research dissertation.

Thanks to all you sincere guys for your efforts
# 7  
Old 09-20-2002
Here is a version of my script that ignores line boundaries during match checking.
Code:
#! /usr/bin/ksh

##  r-r--s
##  r-r--t

longset="[acdefghiklmnpqrstvyz]"
pattern="r${longset}r${longset}${longset}[ts]"

pos=1
linen=0
IFS=""
while read input ; do
        ((linen=linen+1))
        preamble="Line: ${linen} At position"
        input="${save4next}${input}"
        save4next=""
        orig="${input}"
        matches=0
        while ((${#input})) ; do
                if [[ $input = *(?)${pattern}*(?) ]] ; then
                        ((matches=matches+1))
                        leftover=${input#*${pattern}}
                        temp=${input%${leftover}}
                        lead=${temp%${pattern}}
                        this=${temp#${lead}}
                        input="${leftover}"
                        ((pos=pos+${#lead}))
                        echo $preamble $pos MATCH: $this
                        ((pos=pos+${#this}))
                else
                        ((pos=pos+${#input}))
                        if (( ${#input} < 5 )) ; then
                                save4next="${input}"
                        else
                                temp="${input%?????}"
                                save4next="${input#$temp}"
                        fi
                        ((pos=pos-${#save4next}))
                        input=""
                fi
        done
done
exit 0

Note that you cannot have any leading or trailing blanks or tabs on the data lines. I send your data file through this new script and I got:
Code:
Line: 20 At position 953 MATCH: rrrgds
Line: 26 At position 1248 MATCH: rgrfvt
Line: 49 At position 2440 MATCH: rhrars

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

5. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

6. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

7. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

8. Shell Programming and Scripting

Improve script made to calculate value based on present and previous line

Hi all, I have made at small script to make a simple calculation on a file which is formatted in this way: I want to create a new file in which the value of particular line minus the previous line is printed. So my wanted output is: I have made the following program to do the job... (5 Replies)
Discussion started by: s052866
5 Replies

9. Shell Programming and Scripting

How to use Perl to join multi-line into single line

Hello, Did anyone know how to write a perl script to merge the multi-line into a single line where each line with start at timestamp Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; (5 Replies)
Discussion started by: happyday
5 Replies

10. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies
Login or Register to Ask a Question