make script treat * as a regular character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers make script treat * as a regular character
# 1  
Old 10-28-2008
make script treat * as a regular character

I need a script that reads the out put of a command (softwareupdate --list) and will tally up the number of asterisks in the output and tell me how many there were. How do I go about getting my script to treat asterisks as a regular character and not a wildcard or some other operator?
# 2  
Old 10-28-2008
Hammer & Screwdriver here is one approach

Code:
> cat file15
the end is here
and * and more ** are present
i wonder * if * there* more **
than *
** I can count
> tr "*" "~" <file15 | tr "\n" " " | tr "~" "\n" | wc -l
11

Note:
The tr command, sometimes in conjunction with sed and cut, can do so many cool things to translate one character to another. Read the manpages on it to undertand it better.
# 3  
Old 10-28-2008
OMG it was so easy, i got it!
cat outputoffile |grep "*"|wc -l

edit: sorry JoeyG I posted this before i saw what you said, I will try to understand what you wrote. Thanks!
# 4  
Old 10-28-2008
One way -
Code:
softwareupdate --list | tr -dc '*' | wc -c

# 5  
Old 10-28-2008
Thanks guys, this is basically what I think I will use
#!/bin/bash
SU=`softwareupdate --list`

echo $SU |grep "*" |wc -l
# 6  
Old 10-28-2008
Code:
softwareupdate --list |grep "*" |wc -l

Lose the subprocess, the echo and the SU variable. A one-liner like this is not important, but doing what you did in a big script that runs code that uses a lot of resources can eat your system. Or take hours.
# 7  
Old 10-28-2008
Ok, I noticed one problem, there is sometimes a space or two in the output.. how do I get it to ignore the spaces?

This is what I mean:
Software Update Tool
Copyright 2002-2005 Apple

Software Update found the following new or updated software:
* MacProSMCUpdate-1.1
Mac Pro SMC Firmware Update (1.1), 970K [recommended]
* iTunesX-8.0.1
iTunes (8.0.1), 59910K [recommended]
* SecUpd2008-007Intel-1.0
Security Update 2008-007 (Intel) (1.0), 168250K [recommended] [restart]
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add character to specific columns using sed or awk and make it a permanent change

Hi, I am writing a shell script where I want that # should be added in all those lines as the first character where the pattern matches. file has lot of functions defined a.sh #!/bin/bash fn a { beautiful evening sunny day } fn b { } fn c { hello world .its a beautiful day ... (12 Replies)
Discussion started by: ashima jain
12 Replies

2. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

How to use regular exp to replace the character in the file?

Hi Unix Gurus, yesterday I asked a question and got answer, it works fine. I have one more thing need to help in the code awk '{print substr($0,1,3)"xxx"substr($0,7)}' file If I have 50 charactor's need to be replaced, is there any easy way to use reg exp or I have to input 50 XXXXx......... (12 Replies)
Discussion started by: ken6503
12 Replies

4. Shell Programming and Scripting

Make pwd print escape character

I decided I wanted to have the cd command print my full working directory after each cd command, so I put this cw command in .bashrc as a function. cw () { cd "${1}" pwd }While this works I would like pwd to print escapes when a space in a directory name exists. This would... (7 Replies)
Discussion started by: jelloir
7 Replies

5. Shell Programming and Scripting

Make the first character uppercase

Input: hello world monkey Output should be: Hello World Monkey How can it be done with perl,sed,awk or bash? (9 Replies)
Discussion started by: cola
9 Replies

6. UNIX for Dummies Questions & Answers

doubt to treat plaintext script

Hi everyone! first of all thank you all for the forum. My question is, is there a bash or java program, which addresses the existing text in the html that is visible in the web page for editing by another string, eg name1: flakjsdlñfjas Name of father: fdfjaksdfjskdfsd Well it... (1 Reply)
Discussion started by: xavilito
1 Replies

7. Linux

how to grep special character regular expression?

Hi :) I have 2 files file1: SNP_A-2208459 SNP_A-4215188 SNP_A-2012248 SNP_A-1882998 file2: CHR SNP UNADJ BONF HOLM * * * etc. 19 SNP_A-2236481 1.742e-26 5.442e-21 13 SNP_A-4204405 8.643e-07 1.505e-06 3 SNP_A-1860908... (11 Replies)
Discussion started by: sogi
11 Replies

8. Shell Programming and Scripting

How to get the difference between dates?Can i treat as string?

Hi All , I have an output value with two columns like this... Days User 10 A 500 B 1 C How i can compare the first column value and passing the user name as parameter? For example : while read -r days If (days<=30) ; then value=days/30 x100 ... (3 Replies)
Discussion started by: EDBGSK
3 Replies

9. Shell Programming and Scripting

How To Make Decimal Point Fall On The 15th Character On The Screen

If i have a variable which is a decimal number, i.e 34.05 How can you make decimal point fall on the 15th character on the screen? Or any other that you can specify? Can you do it using sed or awk? (3 Replies)
Discussion started by: Vozx
3 Replies
Login or Register to Ask a Question