Want to write all the jar name in single with delimiter ":" in beween the jar name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to write all the jar name in single with delimiter ":" in beween the jar name
# 1  
Old 06-11-2012
Want to write all the jar name in single with delimiter ":" in beween the jar name

Hi All,

I am having 7 jar files in a dir. abc like listed below
HTML Code:
bash-3.00$ cd abc
bash-3.00$ ls
123.jar
23wdawd.jar
dfsa23.jar
dsa.jar
wew234.jar
adsd234234.jar
dfsda423.jar
Now i want to assign all this jar files to a variable in the below format
HTML Code:
AB=123.jar:.:23wdawd.jar:dfsa23.jar:dsa.jar:wew234.jar:adsd234234.jar:dfsda423.jar
Note: 1st delimiter will be ":.:" remaining all will be ":"

Any suggestion on how can i achieve this task?
# 2  
Old 06-11-2012
Code:
ls -1 | awk 'BEGIN{RS=""}{for(i=1;i<=NF;i++) printf("%s%s", i==2 ? ".:"$i : $i, i<NF ? ":" : "\n")}'

# 3  
Old 06-11-2012
Code:
AB=$(ls | paste -sd: - | sed 's/:/:.:/')

Regards,
Alister

Last edited by alister; 06-11-2012 at 02:27 PM.. Reason: Explicitly specify stdin. Thanks, shamrock.
# 4  
Old 06-11-2012
Quote:
Originally Posted by alister
Code:
AB=$(ls | paste -sd: | sed 's/:/:.:/')

Regards,
Alister
Nice one...but to make it work on all flavors of unix the paste command needs to be "paste -sd: -" as legacy unixes dont understand stdin without the - placeholder.
These 2 Users Gave Thanks to shamrock For This Post:
# 5  
Old 06-11-2012
Quote:
Originally Posted by shamrock
Nice one...but to make it work on all flavors of unix the paste command needs to be "paste -sd: -" as legacy unixes dont understand stdin without the - placeholder.
You're absolutely correct. Fixed. Thank you for reminding me of that.

Regards,
Alister
# 6  
Old 06-11-2012
Quote:
Originally Posted by alister
You're absolutely correct. Fixed. Thank you for reminding me of that.

Regards,
Alister
Smilie

---------- Post updated at 01:00 PM ---------- Previous update was at 01:00 PM ----------

Quote:
Originally Posted by alister
Code:
AB=$(ls | paste -sd: - | sed 's/:/:.:/')

Regards,
Alister
Smilie
# 7  
Old 06-12-2012
Thanks to all for the quick response ..... ya i got the output which i required. . . .
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Problems with "write" and "wall"

Hello, I am using VirtualBox to simulate a small network with two Linux computers, the host is Mac OS X. My problem is that I can't send "write" and "wall" messages from the host to one of those Linux computers. Here is what works: - The virtual Linux computer answers "ping" messages that have... (5 Replies)
Discussion started by: 123_abc
5 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Shell Programming and Scripting

Substituting comma "," for dot "." in a specific column when comma"," is a delimiter

Hi, I'm dealing with an issue and losing a lot of hours figuring out how i would solve this. I have an input file which looks like this: ('BLABLA +200-GRS','Serviço ','TarifaçãoServiço','wap.bla.us.0000000121',2985,0,55,' de conversão em escada','Dia','Domingos') ('BLABLA +200-GRR','Serviço... (6 Replies)
Discussion started by: poliver
6 Replies

5. Solaris

How to avoid "cannot execute" issue with a runnable jar file?

I am trying to understand why the runnable jar file runs on one Unix server, but not the other with same environment settings. I copied exact same test jar from here --> http://www.javaworld.com/javaworld/javatips/javatip127/MakeJarRunnable.zip on to both Unix servers. Then changed... (5 Replies)
Discussion started by: kchinnam
5 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Execution problems with the jar -tvf command and "if" logic

Hi, I am reading a directory that has a list of jar files. I am searching these files for specific keywords. What i would like to do is write the address of the jar file to a new file if the search result is returned as false. For example; /home/user/JarDirectory/Examplefile.jar ... (2 Replies)
Discussion started by: crunchie
2 Replies

8. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

9. Shell Programming and Scripting

communicating wth another user aside from "wall" and "write"

Hi, Can anyone suggest a Unix command or c-shell algorithm to simulate to behavior of "wall" command minus the "all users"? What I'm trying to do is to send a notice to just one particular user but i dont want other remotely-logged-on users to receive the message (on the pseudo-terminals). I... (6 Replies)
Discussion started by: Deanne
6 Replies
Login or Register to Ask a Question