HELP | unix | regular expression - How to represent two whitespaces?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers HELP | unix | regular expression - How to represent two whitespaces?
# 1  
Old 10-12-2009
HELP | unix | regular expression - How to represent two whitespaces?

ls -l generates something like...

Code:
-rwxr-xr-x 1 root root   19304 Jan 21  2009 true
-rwsr-xr-x 1 root root   40208 Jan 21  2009 umount
-rwxr-xr-x 1 root root   22336 Jan 21  2009 uname
-rwxr-xr-x 1 root root    1273 Jan 21  2009 unicode_start
-rwxr-xr-x 1 root root      79 Jan 21  2009 unicode_stop
-rwxr-xr-x 1 root root   20576 Jan 21  2009 unlink
-rwxr-xr-x 1 root root   31280 Mar 11  2009 usleep
-rwxr-xr-x 1 root root  632816 Nov 25  2008 vi
lrwxrwxrwx 1 root root       2 Mar  4  2009 view -> vi
lrwxrwxrwx 1 root root       8 Mar  3  2009 ypdomainname -> hostname
-rwxr-xr-x 3 root root   62864 May 28  2008 zcat
-rwxr-xr-x 1 root root  594848 Jan  7  2007 zsh

I want to change each line so that each line has at most one whitespace between characters.

I think I can do this if I knew how to represent two whitespaces. It seems " " or ' ' has the same value as " " or ' '. The first set of quotes have one space and the second set of quotes has two spaces.

I want to be able to take any output that prints into columns and then use something like cut or grep to select futher manipulate the output to only the columns I want. Or something that would tokenize the string. I haven't used sed/awk, but I want to do it with grep, tr or cut preferably.
# 2  
Old 10-12-2009
Hi.

As for your first point:
Code:
ls -l | sed ":h;s/  / /;th"

Got a bit lost after that. What is the end result you want?
# 3  
Old 10-12-2009
Hey, thanks for the reply. sed is a pretty powerful tool.

I was able to do it with tr as well:

Code:
ls -l | tr -s ' '

Still wondering if its possible to do something similar with grep?
# 4  
Old 10-12-2009
You're right. tr works too. I'll remember that one (at least when I'm using Linux). Thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SHELL: UNIX : Ls regular expression not working when used with variables

If i do below command in unix prompt which static values (ie 27..97), it is working fine and gives desired output >ls -d $WORKDIR/batch/somefilename_{27..97}.* 2>/dev/null somefilename_27.sometxt somefilename_28.sometxt somefilename_29.sometxt .. somefilename_97.sometxt But if i want... (2 Replies)
Discussion started by: haiderali
2 Replies

2. Shell Programming and Scripting

Regular expression in UNIX

How can I define a regular expression of a string which can start with Capital alphabet or integer (A-Z) or (0-9) and can be of any number of characters I have tried * but its not working could anyone please suggest? (2 Replies)
Discussion started by: Pratik4891
2 Replies

3. Shell Programming and Scripting

Pattern search (regular expression in UNIX)

Hello , Could anyone help me to define the string in regular expression way . Below is my string \rtf1\ansi\deff0{\fonttbl{\f0\fswiss Helv;}{\f1\fnil MS Sans Serif;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\lang1033\f0\fs16 The string will always start as \rtf1 and... (6 Replies)
Discussion started by: Pratik4891
6 Replies

4. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

5. UNIX for Dummies Questions & Answers

Data analysis, Regular Expression - Unix

Hey every one! I have a dataset like this : 1 100 1 0 5 100 1 8 7 50 1 0 7 100 2 0 10 20 1 8 10 30 1 8 10 100 3 8 15 50 5 0 20 90 1 0 20 99 9 0 I wanna check if the 4th column is 0 or 8 If it's zero write the 1st column itself, if it's 8 write sum of 1st and second something... (2 Replies)
Discussion started by: @man
2 Replies

6. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

7. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

8. UNIX for Dummies Questions & Answers

Help | Unix | grep | regular expression | backreference | Syntax/Logic

Hello, I'm working on learning regular expressions and what I can do with them. I'm using unix to and its programs to experiment and learn what my limitations are with them. I'm working on duplicating the regular expression: ^(.*)(\r?\n\1)+$ This is supposed to delete duplicate lines... (2 Replies)
Discussion started by: MykC
2 Replies

9. UNIX for Dummies Questions & Answers

Help | unix | grep | regular expression

I have the following code: ls -al /bin | tr -s ' ' | grep 'x' ls -al: Lists all the files in a given director such as /bin tr -s ' ': removes additional spaces between characters so that there is only one space grep 'x': match all "x" characters that are followed by a whitespace. I was... (3 Replies)
Discussion started by: MykC
3 Replies

10. UNIX for Dummies Questions & Answers

Syntax Help | unix | grep | regular expression | repetition

Hello, This is my first post so, Hello World! Anyways, I'm learning how to use unix and its quickly become apparent that a strong foundation in regular expressions will make things easier. I'm not sure if my syntax is messing things up or my logic is messing things up. ps -e | grep... (4 Replies)
Discussion started by: MykC
4 Replies
Login or Register to Ask a Question