Reading from keyboard and sorting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading from keyboard and sorting
# 1  
Old 01-24-2013
Reading from keyboard and sorting

Hi,

I ahve come across one of the trickier scenario and wanted to check anyone came across this:
i have a file called file1:
Code:
pandi.desktop% cat file1
aa
cc
ds
wwe
bb
pandi.desktop%

I want to read input from keyboard and append into the original file. besides that i want to sort the whole content and write it to a new file.
i want to accomplish this in a oneliner with out using any '&&' or ';'

Code:
sort - file1>>file2

works but the new content added is not being written in the original file. But the new file comes as expected.
Code:
pandi.desktop% sort - file1>>file2
bbs
cc
ff
pandi.desktop% cat file1
aa
cc
ds
wwe
bb
pandi.desktop% cat file2
aa
bb
bbs
cc
cc
ds
ff
wwe

Thanks in advance
# 2  
Old 01-24-2013
You need to do this in two steps: 1) append stdin to file1 2) sort file1 to file2:
Code:
$ cat >>file1; sort file1 >file2

Or try this:
Code:
$ cat file1 - | tee  file1 | sort >file2

But the second is highly dependent on the timing when the shell opens/closes file1 during creation and execution of the pipe, so it will work more by sheer accident.

Last edited by RudiC; 01-24-2013 at 05:39 AM..
This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem getting vertical bar with British keyboard layout on US (physical) keyboard

Hi, I've got a bit of a ridiculous problem and wasn't sure where to post it. I need to use the vertical bar for piping in Bash but, as per the title, am using a UK layout on a US (physical) keyboard which doesn't have a key for it in the place I'd expect. I've tried using xbindkeys and Unicode... (7 Replies)
Discussion started by: crunchgargoyle
7 Replies

2. Shell Programming and Scripting

Reading from Keyboard - Shell Script

How do i read from kb using shell script but i need to read it from same line. Script :- echo "Please Enter Your Choice " read CHOICE But it goes to next line i need it to read it next to Choice and not new line. (4 Replies)
Discussion started by: dinjo_jo
4 Replies

3. Shell Programming and Scripting

Perl - Reading keyboard keystroke

Hello All, I wounder if any one know if perl have the ability to run script in the background which record each keyboard keystorke? If yes , how can I implement the part which reading the keyboard keystroke? Is there any moudle that handle it ? Thanks a head Alalush (1 Reply)
Discussion started by: Alalush
1 Replies

4. UNIX for Dummies Questions & Answers

what's happening with my keyboard

hi everybody. i ussually use unix and windows, but mainly unix-mandriva distribution, and i have a problem. i have like main os unix, and windows as secondary, and this one is loaded by vmware application. well, when a i load vmware to execute windows afterwards when i return to unix, in this... (1 Reply)
Discussion started by: tonet
1 Replies

5. Programming

reading reading data from webpage

hi iam reading data from web page using request socket and curl socket. now my problem is some the web page containg data as a image so how can i read the data from a image. thank,inadvance. sree (3 Replies)
Discussion started by: phani_sree
3 Replies

6. Linux

mdk 10.2 and keyboard

Hi all, I'm running a mdk 10.2 cooker on my computer. After and update, i've lost the "alt gr" key. How am i supposed to get it back? I've already googled around a bit, testing solutions provided, but nothing can help.. any other suggestions? Thanx all Jason (3 Replies)
Discussion started by: penguin-friend
3 Replies

7. UNIX for Advanced & Expert Users

How can I map Unix keyboard for PC keyboard

A Solaris AXI 440 machine with Solaris 8 version. I have PC users who use an emulation to login to the Solaris server. How can I change the keyboard mapping of the Sun keyboard to fit to the PC keyboard ? Any comment will be appreciated. Thanks (1 Reply)
Discussion started by: simhab
1 Replies
Login or Register to Ask a Question