-
hi peeps, does anyone know how to extract the first 3 character in a text using shell?
I have something like
Code:
for x in `grep "$" dir.txt`
do
set -x
echo $x
awk '{print substr('$x', 1,3)}'
done
which obviously doesnt work because I dont know how to reference a variable inside awk, is this possible? Basivally what I am trying to do is extract the first 3 character of directory names inside dir.txt
Btw is it possible to list just directories but not files using ls -al ?
-
-
ls -l | grep ^d
works if my files are not named with d, for example dir.txt appears :P
-
Code:
for x in `grep "$" dir.txt`
do
echo $x | awk '{print substr($1,1,3)}'
done
Jeff Hunter
-
Originally posted by pando
ls -l | grep ^d
works if my files are not named with d, for example dir.txt appears :P
Works on solaris, ksh. ls -l format is:
drwxrwxrwx 2 owner group filename.txt
You have violated your cardinal rule of specify OS and version...
Jeff Hunter
-
yea try
-rwxrwxrwx 2 owner group dir.txt (not working!)
i am not telling my OS!
ok ok it's windows 2000
-
Tried that, works on my system.
The ^D (carrot D, not ctrl+D) tells grep to look at the first character of the line and ignore the rest.
Code:
dev42:/home/users/jeffh/pando $ ls -l
total 2
-rw-r--r-- 1 jeffh progr 0 Oct 12 17:23 dir.txt
drwxr-xr-x 2 jeffh progr 512 Oct 12 17:24 mydir
-rw-r--r-- 1 jeffh progr 0 Oct 12 17:23 readme.txt
dev42:/home/users/jeffh/pando $ ls -l | grep ^d
drwxr-xr-x 2 jeffh progr 512 Oct 12 17:24 mydir
Jeff Hunter
-
hmm may be MKS is not working properly in win 2k will try it on redhat later
-
The work of regular expressions
Sam
Thanx
Sam
Life is a journey, not a destination!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|