Need Help in Cutting a word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help in Cutting a word
# 1  
Old 09-20-2008
Need Help in Cutting a word

Hi All ,

i am working on a backup script , which would a call a executable file in unix server ,

Login credentials ::

use telnet session to login to Unix server

when logged in, this would be my Prompt :::

unix11@raghav:

I just need to cut the word unix11 , so that i can use this to set my path to call the executable ::

Please help me on this


Thanks all for your Help !!!
# 2  
Old 09-20-2008
Code:
echo "unix11@raghav" | awk -F"@" '{ print $1}' | read firstword
echo $firstword

# 3  
Old 09-20-2008
Thanks!! but my server name doesnot be constant ..

we use several unix machines. is there any way to cut that part when i login

instead of giving them in echo ???

Thanks!!
# 4  
Old 09-20-2008
well - your prompt could be set to be most anything usually using the PS1 variable - I'm guessing that unix11 is the username you connected as, in which case you could use one of:

id
$USER / $user variable
whoami

etc

to see what your prompt looks like use echo $PS1

(and to answer your question try echo unix11@raghav | sed 's/@.*//' )

Code:
 echo unix11@raghav | sed 's/@.*//'
or
 echo unix11@raghav | cut -d@ -f1
or
  echo unix11@raghav | awk -F"@" '{print $1}'

HTH
# 5  
Old 09-20-2008
The PS1 environment variable is how the prompt is defined. Try the echo trick on that variable, or use one of the string operations on the variable - the ones in shell.

What shell?
Code:
echo $SHELL

will tell you your shell.
# 6  
Old 09-21-2008
Thanks for your reply

thats not my id , its my server name .. and if i cannot cut those server name is there a possibility to create in link from the source directory to target .

so that when i run the shell script it calls this executable and performs the functions ..

i have only two servers one is unix11 and unix 12 .. in these i have the executables in bin directory . If i create a link in my local directory will that work ???

also let me know how to create a link for a file so that it would be very helpful !!!

Thanks again for your help !!!!
# 7  
Old 09-23-2008
i tried to call the executable by creating a link

ln -s

but it didnot work can anyone let me know how this can be performed!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies

3. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

4. Shell Programming and Scripting

AWK Substring without cutting off word

Can someone help me to make this code without cutting off words ni the string? awk '{for(i=1;i<length;i+=100) print substr($0,i,100)}' Thank you! (4 Replies)
Discussion started by: sanantonio7777
4 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Shell Programming and Scripting

Perl Cutting character(s) from a word

Hello, How to cut a char(s) for a word using perl?? I want to cut the number(s) from these sample words: Port-channel24 Po78 Po99 Port-channel34 $word = "Port-channel24"; I want to put only the number in a varible. Appreaciate using simple way in order to use it... (3 Replies)
Discussion started by: ahmed_zaher
3 Replies

7. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

8. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

9. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

10. UNIX for Dummies Questions & Answers

cutting

Is there any cut or awk function that would allow me to take the last part of a path away and save the list into a file? I wrote: find $HOME -mtime +3 > fileList cat fileList /home/102/s/jn/folder/HW /home/102/s/jn/otherfolder/B.txt /home/102/s/jn/folder4/3dA/w... (1 Reply)
Discussion started by: terms5
1 Replies
Login or Register to Ask a Question