1831806 Members
2488 Online
110029 Solutions
New Discussion

About the script

 
SOLVED
Go to solution
juno2
Super Advisor

About the script

I am beginner of script writing, I know this is the simple question but I still can't find the solution, pls help.

my question is how to use "cut" to cut the result .

# cat abc.txt
# abcdefghij

I would like to write a script to cut the result as "abcghi" ? thx.
19 REPLIES 19
steven Burgess_2
Honored Contributor

Re: About the script

Hi

cat abc.txt | cut -c1-3,7-9

Have a look at the man pages for cut.It will give you examples at the end

HTH

Steve
take your time and think things through
Francisco J. Soler
Honored Contributor
Solution

Re: About the script

Hi, Juno, you can try

cut -c1-3,7-11 abc.txt

Frank.
Linux?. Yes, of course.
V. V. Ravi Kumar_1
Respected Contributor

Re: About the script

hi,

# cut -c1-3,7-9 abc.txt

Regards

Never Say No
Balaji N
Honored Contributor

Re: About the script

hi juno,

u have got the answers already. may i request you to spend some time reading a book on shell programming.

and, next time before you post a question, have a look at this.

http://www.catb.org/~esr/faqs/smart-questions.html

sorry, i dont mean to offend.
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
juno2
Super Advisor

Re: About the script

thx all , but how to make the result as "abcde fghij" ? thx.
H.Merijn Brand (procura
Honored Contributor

Re: About the script

# sed 's/ef/e f/' infile

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
juno2
Super Advisor

Re: About the script

Another simple question about writing script,

i have find out some process id and save it to a file - "/tmp/dead_pid" as below,
# more /tmp/dead_pid
4584
2548
5844
"
"

except
#kill 4584
#kill 2548
#kill 5844

How can I set a script to kill these process for one time? thx.
Balaji N
Honored Contributor

Re: About the script


cat /filename | xargs -l kill -TERM

-balaji

ps: how abt assigning points
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
juno2
Super Advisor

Re: About the script

thx all & thx Balaji N .
juno2
Super Advisor

Re: About the script

I still hv one more simple similiar question , how to use the xargs and grep at the same time?
eg.

if i have a file "/tmp/file1"

# more /tmp/file1
pts/1
pts/2
pts/3

except use
# ps -ef |grep pts/1
# ps -ef |grep pts/2
# ps -ef |grep pts/3

how to find the result for one time ?
Balaji N
Honored Contributor

Re: About the script

man grep.

[balajin@redpenguin balajin]$ cat /tmp/file1
pts/1
pts/2
pts/3
[balajin@redpenguin balajin]$ grep -e "pts/1" -e "pts/2" -e "pts/3" /tmp/file1
pts/1
pts/2
pts/3


-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Balaji N
Honored Contributor

Re: About the script

and pls read some documents / books on shell scripting.
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
juno2
Super Advisor

Re: About the script

hi Balaji N ,

thx r reply , but my question is ,

# more /tmp/file1
pts/1
pts/2
pts/3

except use
# ps -ef |grep pts/1
# ps -ef |grep pts/2
# ps -ef |grep pts/3

how to find the result , I would like the result as :
acc_usr 14585 14584 0 14:34 pts/22 00:00:00 [_ll]
root 14928 30712 0 15:10 ? 00:00:00 in.telnetd: 168.162.0.1
root 14929 14928 0 15:10 ? 00:00:00 [login]
edp_usr 14930 14929 0 15:10 pts/24 00:00:00 -bash
V. V. Ravi Kumar_1
Respected Contributor

Re: About the script

hi,

to kill the processes that u have /tmp/file1, u can do
# for i in `cat /tmp/file1`
> do
> kill -9 $i
>done

to grep process ids
# for i in `cat /tmp/file1`
> do
> ps -ef|grep $i >> /tmp/pids
>done

here file /tmp/pids contains the list of all processes which matches to those in the file /tmp/file1

Regards
Never Say No
Balaji N
Honored Contributor

Re: About the script

hi
i cant understand your question completely. no relation between what u show in the files and the output you want?
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
juno2
Super Advisor

Re: About the script

in other way, I just want to run "ps -ef" to find all tty in file1 , my result should like this
acc_usr 14585 14584 0 14:34 pts/22 00:00:00 [_ll]
root 14928 30712 0 15:10 ? 00:00:00 in.telnetd: 168.162.0.1
root 14929 14928 0 15:10 ? 00:00:00 [login]
edp_usr 14930 14929 0 15:10 pts/24 00:00:00 -bash

what can i do? thx
Balaji N
Honored Contributor

Re: About the script

the above example shown by ravi kumar demonstrates that.

-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Paula J Frazer-Campbell
Honored Contributor

Re: About the script

Good Day

Please note :-

This member has assigned points to 79 of 241 responses to his/her questions.


If these members have assisted you then please assign points.

Paula
If you can spell SysAdmin then you is one - anon
john korterman
Honored Contributor

Re: About the script

Hi,
I assume that you want to have displayed the processes associated with the terminals described in /tmp/file1. If this is correct, then try this simple script, show_procs.sh:


#!/usr/bin/sh
while read TERM
do
ps -ft$TERM| grep -v COMMAND
done <$1

And run it like this:
# show_procs.sh /tmp/file1


regards,
John K.
it would be nice if you always got a second chance