excluding a character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting excluding a character
# 1  
Old 01-12-2004
excluding a character

Hi,
I want to compare the percentage value from the df -k output for which I'm doing:
df -k|grep u01|awk '{print $4}'
--this returns with % sign, how do i exclude this??
-Karthik
# 2  
Old 01-13-2004
You're really close - you can add to the end of that:

| sed 's/%//'
# 3  
Old 01-13-2004
Or do it all in awk...

df -k | awk '/u01/ {sub("%","",$4); print $4}'
# 4  
Old 01-13-2004
thank you guys
# 5  
Old 01-13-2004
Quote:
Originally posted by Ygor
Or do it all in awk...

df -k | awk '/u01/ {sub("%","",$4); print $4}'
Even better! awk and sed are tough commands to master but incredibly powerful; I wish I knew them thru and thru...
# 6  
Old 01-13-2004
Much of the real power behind many of the tools in UNIX comes from an understanding of "regular expressions".

A coulple of nice sites to visit and learn from:

http://www.regular-expressions.info/
http://en2.wikipedia.org/wiki/Regular_expression

A little history (from wikipedia):

A regular expression (abbreviated as regexp or regex) is a string that describes a whole set of strings, according to certain syntax rules. These expressions are used by many text editors and utilities (especially in the Unix operating system) to search bodies of text for certain patterns and, for example, replace the found strings with a certain other string.

The origin of regular expressions lies in automata theory and formal language theory (both part of theoretical computer science). These fields study models of computation (automata) and ways to describe and classify formal languages. A formal language is nothing but a set of strings. In the 1940s, Warren McCulloch and Walter Pitts described the nervous system by modelling neurons as small simple automata. The mathematician, Stephen Kleene, later described these models using his mathematical notation called regular sets. Ken Thompson built this notation into the editor qed, then into the Unix editor ed and eventually into grep. Ever since that time, regular expressions have been widely used in Unix and Unix-like utilities such as: expr, awk, Emacs, vim, lex, and Perl. Most tools use an implementation of the regex library built by Henry Spencer.

Cheers,

Keith
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rm * excluding one file

Hi All, I am trying to remove below file except the last one. With wild char It is removing all. Is there a way to exclude only one file and remove files: MM_6000_001 MM_6000_002 MM_6000_003 MM_6000_004 if I do rm * it is removing all. I want the exclude and remove others. any... (14 Replies)
Discussion started by: arunkumar_mca
14 Replies

2. Shell Programming and Scripting

Excluding the unwanted rows

# Total Table name -----------------------+--------+--------------------------------+--------------------------+--------------- GK_AMP GK_AMP GK_AMP GK_AMP GK_AMP GK_AMP (6 how can i extract only table name excluding other lines ?pls suggest (4 Replies)
Discussion started by: rocking77
4 Replies

3. Shell Programming and Scripting

Excluding directories from a find

I've looked at a few similar threads, but I can't bridge from those examples to what I'm working on, so I'm hoping someone can help. I want to extend the following statement find $PathToCheck -type f \( -not -iwholename "$ScriptDir/*" \) -exec md5sum "{}" \;>$NewSigs to exclude several... (9 Replies)
Discussion started by: nixie
9 Replies

4. Shell Programming and Scripting

Help needed in excluding word

Hello, When i run this command find ./ -type f -print | xargs grep -l 'myWord' it prints the file name where 'myWord' exists and also something like the below which i want to exclude grep: can't open Fields grep: can't open Search I tried piping and grep -v 'open' but it did not work. ... (3 Replies)
Discussion started by: jakSun8
3 Replies

5. Shell Programming and Scripting

Excluding a directory

i want to search files in public_html of all users and exclude any directories named "uploads" or "albums" (because there are many files in these), just skip them completely now im doing something like find /home/*/public_html -regex ".*\(php\|html\|htm\)$" -path albums -prune -o -type f... (1 Reply)
Discussion started by: vanessafan99
1 Replies

6. Shell Programming and Scripting

Excluding directory during deleting

Hi all, I'm trying to work on a script to delete files older then 31 day's in certain directories. Now, that works, but in one directory there are 3 other maps which contains files that can be deleted but one map which contains files that can't be deleted. My current command is: find... (6 Replies)
Discussion started by: JasperG
6 Replies

7. Shell Programming and Scripting

Excluding file from tar

Hello i am using HP-UX rapdb2 B.11.23 U ia64 1068321383 unlimited-user license. I am tryiyng to exclude for tar all files that start with TOT* but i doues not work I am using: tar -cvf /ODS/prepaid/CDR_FLOW/WORK/backup.tar --exclude='TOT*' and i get the error: tar: cannot stat... (3 Replies)
Discussion started by: chriss_58
3 Replies

8. UNIX for Advanced & Expert Users

Excluding a file from tar...

The title is not as easy as it sounds.... I am trying to exclude and file while ssh and untaring the file on the fly. The command I am using is... The command typically works but recently I've add the X option along with the exclude file. Essentially, the exclude file is being ignored when run... (2 Replies)
Discussion started by: lwif
2 Replies

9. Shell Programming and Scripting

cp -Rp excluding certain files?

Hi, I'm using cp -Rp to copy directories while preserving permissions. I want to exclude any ".lproj" files except for "English.lproj" and "en.lproj" from being copied, but the rest is copied as usual. Is there a way to do this (without using tar or other compression utilities) Thanks (3 Replies)
Discussion started by: pcwiz
3 Replies

10. Shell Programming and Scripting

cp -r excluding certain directories?

I want to recursively copy /home/me/someProject/* to a /home/you/ but I want to exclude directories called "classes". I can't find any option for excluding certain directories. Does such a thing exist, or any workaround, or am I missing something obvious> (2 Replies)
Discussion started by: sarnobat
2 Replies
Login or Register to Ask a Question