UNIX Pipelines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX Pipelines
# 1  
Old 10-10-2013
UNIX Pipelines

What if you want to have just one single pipeline that will create a file (let's say x) and we want all the content from another file (we can call it y), one word per line?
# 2  
Old 10-10-2013
Code:
awk '{ for (i=1;i<=NF;++i) {print i"\n"}}' y > x

# 3  
Old 10-10-2013
Interesting question. If you really want to use a single pipe, how about the following?
Code:
$ cat infile
The quick brown fox jumped
over the fence
and ran into the woods

$  tr '[:space:]' '\n' < infile | cat - > outfile

$ cat outfile
The
quick
brown
fox
jumped
over
the
fence
and
ran
into
the
woods

# 4  
Old 10-10-2013
Code:
tr -s ' \011' '\012' <input.txt >output.txt

There's a space at the front of the tr first quoted arg. The 011 matches a tab. Assumes a *ix env with 012 (octal) linefeeds.
# 5  
Old 10-11-2013
Quote:
Originally Posted by cjcox
Code:
tr -s ' \011' '\012' <input.txt >output.txt

There's a space at the front of the tr first quoted arg. The 011 matches a tab. Assumes a *ix env with 012 (octal) linefeeds.
The character class [:space:] is more portable since it covers all whitespace in all locales.
# 6  
Old 10-15-2013
Portable meaning contemporary Unix/Linux... yes... then I agree with your statement.
# 7  
Old 10-15-2013
Code:
xargs -n1 <infile >outfile

Code:
$ cat infile
The quick brown fox jumped
over the fence
and ran into the woods
$ xargs -n1 <infile >outfile
$ cat outfile
The
quick
brown
fox
jumped
over
the
fence
and
ran
into
the
woods
$

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Transfer from Window server to UNIX and UNIX to UNIX

Dear All, Can someone help to command or program to transfer the file from windows to Unix server and from one unix server to another Unix server in secure way. I would request no samba client. (4 Replies)
Discussion started by: yadavricky
4 Replies

2. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

3. UNIX for Dummies Questions & Answers

Building Pipelines?

How would I combine commands in a pipeline to produce an alphabetized list of who's online at a particular moment? Then: How would I take that pipeline and turn it into a command called "whoison"? (1 Reply)
Discussion started by: greeky
1 Replies

4. Shell Programming and Scripting

Varialble in pipelines

Hi, As per shell docs because commands in pipelines are run as separate processes, variables set in a pipeline have no effect on the parent shell In the sample below I am unable to set variable in Proc1 so that I can see it in the main program Is there any work around ? Thanks Zam... (4 Replies)
Discussion started by: zam
4 Replies

5. UNIX for Dummies Questions & Answers

Pipelines

Now before this thread gets closed, please be aware this is not classwork or homework, I am trying to learn unix by myself, and have come stuck below. So it is a pointless to close this thread, as I am trying to improve my unix by asking advice from people. That is what I assume a forum is for! ... (1 Reply)
Discussion started by: Vn3050
1 Replies

6. Shell Programming and Scripting

FTP script for sending a file from one unix directory to another unix server director

Hi, My local server is :/usr/abcd/ Remote server is :/Usr/host/test/ I want to send files from local unix directory(All files starting with O_999) to remote host unix directory. Can any body give me the Unix Shell script to do this. One more doubt: Shall we need to change the file... (1 Reply)
Discussion started by: raja_1234
1 Replies

7. UNIX for Advanced & Expert Users

missing Path(in UNIX) when i launch a job on to unix machine using windows SSh

hi i want run an unix application from a windows program/application.i am using SSH(command line version)to log on to a unix machine from windows. the application has to read a configuration file inorder to run. the configuration file .CFG is in bin in my home directory. but the application... (1 Reply)
Discussion started by: megastar
1 Replies

8. UNIX for Dummies Questions & Answers

multiple pipelines

howdy all, i've been trying to find info on piping info between multiple commands from the command line, but i've been unable to find any examples of piping continuous data through a chain of commands. basically, i'm trying to parse data from the top command and send it out over udp to another... (1 Reply)
Discussion started by: ohhmyhead
1 Replies

9. UNIX for Dummies Questions & Answers

UNIX problem? Unix programm runs windows 2000 CPU over 100%

Okee problems...!! What is happening: Unix server with some programms, workstations are windows 2000, the workstations work good but when you start a programm on the Unix server the CPU of the workstations go to 100% usage resulting that the system gets very slow. The programm well its running so... (2 Replies)
Discussion started by: zerocool
2 Replies
Login or Register to Ask a Question