Pairing the nth elements on multiple lines iteratively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pairing the nth elements on multiple lines iteratively
# 8  
Old 08-04-2015
Thanks again for the reply.

LaTeX requires a blank space after some commands (or '{}'), which creates problems if blank spaces are word delimiters.

I had been assuming that it might be possible to use '} {' as a word delimiter, rather than a space, but then that would run into complications with the 3rd and fourth lines, where there are no '} {' delimiters.

So, below I've replaced all of the blank spaces within words with '{}' which will hopefully help. Thanks.

Code:
\gla {itl\'i\textglotstop{}} {k\textsuperscript{w}uk\textsuperscript{w}} {t\textschwa{}cx\textsuperscript{w}\'u\texthalflength\texthalflength{}y.}//   
\glb {itl\'i\textglotstop{}} {k\textsuperscript{w}uk\textsuperscript{w}} {tc+\ts{}x\textsuperscript{w}\'uy}// 
\glc \textsc{dem} \textsc{rep} \textsc{loc}+go //  
\glc from.there they.say came.over.this.way // 
\glft `They said he was coming along.' //    

\gla {u\textbeltl{}} {cut} {k\textsuperscript{w}uk\textsuperscript{w}} {al\'a\textglotstop{}} {lut} {i\textglotstop{}} {q\'aqx\textsuperscript{w}\textschwa{}lx} {ka\textglotstop} {cx\textsuperscript{w}uys} {i\textglotstop{}} {l} {siw\textbeltl{}k\textsuperscript{w}.} //  
\glb {u\textbeltl{}} {cut} {k\textsuperscript{w}uk\textsuperscript{w}} {al\'a\textglotstop{}} {lut} {i\textglotstop{}} {q\'a(\tb)\ts{}qx\textsuperscript{w}lx} {ki\textglotstop} {c\textendash{}\ts{}x\textsuperscript{w}uy\textendash{}s} {i\textglotstop{}} {l} {siw\textbeltl{}k\textsuperscript{w}} //  
\glc \textsc{conj} say \textsc{rep} \textsc{dem} \textsc{neg} \textsc{det} fish \textsc{comp.obl} \textsc{cust}\textendash go\textendash \textsc{3sg.poss} \textsc{det} \textsc{loc} water //  
\glc and he.said they.say here no the fish where.that they.come the through water //  
\glft `Coyote said there will be no fish going through the water here.' //

# 9  
Old 08-04-2015
Quote:
Originally Posted by John Lyon
Thanks again for the reply.

LaTeX requires a blank space after some commands (or '{}'), which creates problems if blank spaces are word delimiters.

I had been assuming that it might be possible to use '} {' as a word delimiter, rather than a space, but then that would run into complications with the 3rd and fourth lines, where there are no '} {' delimiters.

So, below I've replaced all of the blank spaces within words with '{}' which will hopefully help. Thanks.

Code:
\gla {itl\'i\textglotstop{}} {k\textsuperscript{w}uk\textsuperscript{w}} {t\textschwa{}cx\textsuperscript{w}\'u\texthalflength\texthalflength{}y.}//   
\glb {itl\'i\textglotstop{}} {k\textsuperscript{w}uk\textsuperscript{w}} {tc+\ts{}x\textsuperscript{w}\'uy}// 
\glc \textsc{dem} \textsc{rep} \textsc{loc}+go //  
\glc from.there they.say came.over.this.way // 
\glft `They said he was coming along.' //    

\gla {u\textbeltl{}} {cut} {k\textsuperscript{w}uk\textsuperscript{w}} {al\'a\textglotstop{}} {lut} {i\textglotstop{}} {q\'aqx\textsuperscript{w}\textschwa{}lx} {ka\textglotstop} {cx\textsuperscript{w}uys} {i\textglotstop{}} {l} {siw\textbeltl{}k\textsuperscript{w}.} //  
\glb {u\textbeltl{}} {cut} {k\textsuperscript{w}uk\textsuperscript{w}} {al\'a\textglotstop{}} {lut} {i\textglotstop{}} {q\'a(\tb)\ts{}qx\textsuperscript{w}lx} {ki\textglotstop} {c\textendash{}\ts{}x\textsuperscript{w}uy\textendash{}s} {i\textglotstop{}} {l} {siw\textbeltl{}k\textsuperscript{w}} //  
\glc \textsc{conj} say \textsc{rep} \textsc{dem} \textsc{neg} \textsc{det} fish \textsc{comp.obl} \textsc{cust}\textendash go\textendash \textsc{3sg.poss} \textsc{det} \textsc{loc} water //  
\glc and he.said they.say here no the fish where.that they.come the through water //  
\glft `Coyote said there will be no fish going through the water here.' //

Huh??? The only difference in the 9th line in this sample and your previous sample is that there are two spaces following the // at the end of the line here when there was only one space following the // on that line in your previous sample!

If you could modify you input so that braces surrounded words on all lines (with the possible exception of the \glft lines) as you are currently doing with the \gla and \glb lines, that would make it easy to do what you want. Hybrid lines (as you said this example would provide) would be possible to process (but will require more complex code).
# 10  
Old 08-05-2015
python

Code:
with open("b.txt") as file:
	lines=file.readlines()
a=[
	[
		i[j]
		for i in 
		[
			j for j in [j.split(" ") for j in [line.replace("\n","") for line in lines ]]
		]
	]
	for j in range(len(lines[0].split(" ")))
]


for i in a[1:]:
	print(" ".join(i))

awk

Code:
awk '{
        for(i=1;i<=NF;i++){
                arr[i""NR]=$i
        }
        col=NF
        row=NR
}
END{
        for (i=2;i<=NF;i++){
          for (j=1;j<=NR;j++)
            printf("%s ", arr[i""j])
          print ""
}
}' a

# 11  
Old 08-08-2015
Thanks very much again for the replies, I'll be travelling for the next couple weeks but will pick up this thread when I'm back.
# 12  
Old 08-08-2015
Quote:
Originally Posted by John Lyon
Thanks very much again for the replies, I'll be travelling for the next couple weeks but will pick up this thread when I'm back.
If the thread times out and is closed when you get back, send me a private message and I'll reopen it for you. (Don't start another thread; there is a lot of context here that we don't want to repeat in a new thread.)
# 13  
Old 08-09-2015
This is building on Don Cragun's proposal in post#2 but extends it to deal with multiple data sets in one or more files. Unfortunately the problem with "spaces in words" in the \\glc- lines could not be solved and had to be dealt with manually (replaced them by underscores). Except for this, the output is close to what you desired in post#6:
Code:
awk '
/^\\glft/       {next
                }
/^\\gla/        {gsub ("} {", "}\&{")
                 BEG=MX
                 MX=NF 
                 DLT=NR-1
                }
/^\\glb/        {gsub ("} {", "}\&{")
                }
/^\\glc/        {sub (" ", "")
                 sub ("[ /]*$", "")
                 gsub(" ", "\&")   
                }

                {sub (/\\gl[abc] */,_)
                 $1=$1
                 for (i = 1; i <= NF; i++)
                        {o[i + BEG, NR - DLT] = $i
                        }
                }

END             {for(i = 1; i <= BEG+MX; i++)
                        for(j = 1; j <= 4; j++)
                                printf ("%s%s", o[i, j], j == 4 ? ORS : OFS)
                }
' FS="&"  OFS=" & " file | sort -u
{al\'a\textglotstop } & {al\'a\textglotstop } & \textsc{dem} & here
{cut} & {cut} & say & he.said
{cx\textsuperscript{w}uys} & {c\textendash \ts x\textsuperscript{w}uy\textendash s} & \textsc{cust}\textendash_go\textendash_\textsc{3sg.poss} & they.come
{i\textglotstop } & {i\textglotstop } & \textsc{det} & the
{itl\'i\textglotstop } & {itl\'i\textglotstop } & \textsc{dem} & from.there
{ka\textglotstop} & {ki\textglotstop} & \textsc{comp.obl} & where.that
{k\textsuperscript{w}uk\textsuperscript{w}} & {k\textsuperscript{w}uk\textsuperscript{w}} & \textsc{rep} & they.say
{l} & {l} & \textsc{loc} & through
{lut} & {lut} & \textsc{neg} & no
{q\'aqx\textsuperscript{w}\textschwa lx} & {q\'a(\tb)\ts qx\textsuperscript{w}lx} & fish & fish
{siw\textbeltl k\textsuperscript{w}.} //  & {siw\textbeltl k\textsuperscript{w}} //  & water & water
{t\textschwa cx\textsuperscript{w}\'u\texthalflength\texthalflength y.}//   & {tc+\ts x\textsuperscript{w}\'uy}//  & \textsc{loc}+go & came.over.this.way
{u\textbeltl } & {u\textbeltl } & \textsc{conj} & and

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare multiple arrays elements using awk

I need your help to discover missing elements for each box. In theory each box should have 4 items: ITEM01, ITEM02, ITEM08, and ITEM10. Some boxes either have a missing item (BOX02 ITEM08) or might have da duplicate item (BOX03 ITEM02) and missing another one (BOX03 ITEM01). file01.txt ... (2 Replies)
Discussion started by: alex2005
2 Replies

2. UNIX for Dummies Questions & Answers

Getting the lines with nth column non-null

Hi, I have a huge list of archives (.gz). Each archive is about 40MB. A file is generated every minute so if I want to analyze the data for 1 hour I get already 60 files for example. These are text files, ';' separated, each line having about 300 fields (columns). What I need to do is to... (11 Replies)
Discussion started by: Nenad
11 Replies

3. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

4. UNIX for Dummies Questions & Answers

Rename multiple files in shell bash, changing elements order.

Hi, I want to rename several files like this: example: A0805120817.BHN A0805120818.BHN ..... to: 20120817.0805.N 20120818.0805.N ...... How can i do this via terminal or in shell bash script ? thanks, (6 Replies)
Discussion started by: pintolcv
6 Replies

5. Shell Programming and Scripting

Extracting lines after nth LINE from an output

Hi all, Here is my problem for which i am breaking my head for past three days.. I have parted command output as follows.. Model: ATA WDC WD5000AAKS-0 (scsi) Disk /dev/sdb: 500GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type ... (3 Replies)
Discussion started by: selvarajvs
3 Replies

6. Shell Programming and Scripting

How to output all lines following Nth occurrence of string

Greetings experts. Searched the forums (perhaps not hard enough?) - Am searching for a method to capture all output from a log file following the nth occurrence of a known string. Background: Using bash, I want to monitor my Oracle DB alert log file. The script will count the total # of... (2 Replies)
Discussion started by: cjtravis
2 Replies

7. Shell Programming and Scripting

Array output through a for loop problematic with multiple elements.

This code works perfect when using a machine with only one interface online. (Excluding the loopback of course) But when I have other interface up for vmware or a vpn the output gets mixed up. I know I had this working when I was just reading ip's from files so I know it is not a problem with... (8 Replies)
Discussion started by: Azrael
8 Replies

8. UNIX for Dummies Questions & Answers

Finding nth line across multiple files

I have several files (around 50) that have the similar format. I need to extract the 5th line from every file and output that into a text file. So far, I have been able to figure out how to do it for a single file: $ awk 'NR==5' text1.txt > results.txt OR $ sed -n '5p' text1.txt > results.txt... (6 Replies)
Discussion started by: oriqin
6 Replies

9. UNIX for Dummies Questions & Answers

Getting number of lines of nth occurrency

Hi all, I would like to extract the line number of the n-th occurrency of a given string in a file. e.g. xxx yyy xxx zzz xxx the second occurrency of xxx is at line 3. What is the fastest way to do it in bash? Thank you, (8 Replies)
Discussion started by: f_o_555
8 Replies

10. Shell Programming and Scripting

Average of elements throught multiple files

Hi, I got a lot of files looking like this: 1 0.5 6 All together there are ard 1'000'000 lines in each of the ard 100 files. I want to build the average for every line, and write the result to a new file. The averaging should start at a specific line, here for example at line... (10 Replies)
Discussion started by: chillmaster
10 Replies
Login or Register to Ask a Question