UNIX trick or command

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers UNIX trick or command
# 8  
Old 02-09-2017
Just for the fun of it - might make me eligible for some "science of stupid award"...
Code:
paste -d"A_\nB_" /dev/null /dev/null file /dev/null /dev/null file
A_Ant
B_Ant
A_Bat
B_Bat
A_Cat
B_Cat
A_Dog
B_Dog

These 2 Users Gave Thanks to RudiC For This Post:
# 9  
Old 02-10-2017
You'll get my recommendation Smilie You know I love these Smilie .


It could be shortened a little still::
Code:
paste -d"A_\nB_" - - file - - file </dev/null

This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 02-13-2017
Why am I always late to this kind of thing?
Code:
while read line
do
   printf "%s\n" {A_,B_}$line
done

# 11  
Old 02-13-2017
Nice, but please add quotes around variables in command arguments!
Code:
while read line; do printf "%s\n" {A_,B_}"$line"; done < file

# 12  
Old 02-13-2017
Quote:
Originally Posted by MadeInGermany
Nice, but please add quotes around variables in command arguments!
You're right, of course. I forgot them in my haste to post that suggestion.

Andrew
# 13  
Old 02-13-2017
Another sed-solution:

Code:
sed 's/^/A_/p;s/^./B/' file

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Vi search starting from line n --- any trick for this ???

Hi all, It does not seem to be possible to use vi to search from text from line n forward or backward or is there a not well known vi trick to do that? What I am trying to do is for example I am on line 100 and I want to search from line 100 backward or forward for a specific text. Using /... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Programming

Oracle TRICk Question

HI Guys , Below are the two columns ITEMS and STATE of table . ITEMS STATE '2345','ggdh','k5tg','dgyt','hFF' DF '1234','ghyt','DDD','GHTD','ABF' PQ Can we get output in PL/SQL in below way ?... (7 Replies)
Discussion started by: Perlbaby
7 Replies

3. UNIX for Dummies Questions & Answers

alternative to the grep trick

Hi, We used to use the below commands often. ps -ef|grep bc ps -ef|grep abc|grep -v grep Both fairly returns the same result. For example, the process name is dynamic and we are having the process name in a variable, how we can apply the above trick. For example "a" is the... (11 Replies)
Discussion started by: pandeesh
11 Replies

4. UNIX for Dummies Questions & Answers

A trick to avoid ESC in vim

Hello, I find a trick to avoid pressing ESC without key-maping in vim. I am pleasure using this method, because ALT key is very comfortble for thumb to press. What's the trick? the ALT key. When you are in INSERT mod, press ALT+l switch to COMMAND mod without... (2 Replies)
Discussion started by: vistastar
2 Replies

5. Shell Programming and Scripting

Any trick to speed up script?

Hi Guys, I have a script that I am using to convert some text files to xls files. I create multiple temp. files in the process of conversion. Other than reducing the temp. files, are there any general tricks to help speed up the script? I am running it in the bash shell. Thanks. (6 Replies)
Discussion started by: npatwardhan
6 Replies

6. Shell Programming and Scripting

Trick to ignore space in folder name

Hello All, I am getting error while passing a folder name that has space to the cmd line argument. sh log_delete2.sh "/home/kumarpua/TESTARTIFACTS/atf-chix/ATF-subversion-dev/ssenglogs/A RM" log_delete2.sh: line 17: cd: /home/kumarpua/TESTARTIFACTS/atf-chix/ATF-subversion-dev/ssenglogs/A:... (3 Replies)
Discussion started by: pulkit
3 Replies

7. UNIX for Dummies Questions & Answers

Looking for tips ant trick extend vi

Hello im looking for sites or tutorials how to extend vi (not vim) for programming and scripting beyond simple editing . Thanks allot (0 Replies)
Discussion started by: umen
0 Replies

8. Shell Programming and Scripting

Stupid find trick

At work, we use a software development product (from a company that will remain nameless, but whose name may be considered a synonym for "logical"). The development trees are organized beneath a top directory, let's call it "$rat". The first level under $rat contains the major system names, and... (2 Replies)
Discussion started by: criglerj
2 Replies
Login or Register to Ask a Question