Hello All,
I have a sequence value like
2
2a
3
3a
when I execute this command
ls -1v *.sql | cat -n | grep 2 | awk ' { print $1 } '
it greps 2 and 3 which is 2 and 2a. I want the output to only display 3 ie, 2a.
[oracle@ccoshs02xvdbs02 deploy]$ ls -1v *.sql
1.taba.sql
2.tab2.sql
2a.ta.sql
3.view.sql
3a.se.sql
4.cons.sql
Thanks.
agama
September 6, 2010, 2:05pm
2
I'm not sure I understand what your requirements are.
If you want to find all filenames that have two characters before the first dot (.), and grep through just those files, then something like this might be more suited:
ls -1v ??.* | xargs grep 2 | awk '{ print $1; }'
If you specifically need one character followed by 'a.' then use the file pattern ?a.* on the ls command.
Aia
September 6, 2010, 2:15pm
3
r_bastawala:
[...]
it greps 2 and 3 which is 2 and 2a. I want the output to only display 3 ie, 2a.
[oracle@ccoshs02xvdbs02 deploy]$ ls -1v *.sql
1.taba.sql
2.tab2.sql
2a.ta.sql
3.view.sql
3a.se.sql
4.cons.sql
Thanks.
Do I understand that out that output you only want?
2a.ta.sql
3.view.sql
Correct?
ls -1v *.sql | awk '/2a\.|3\./ {print NR, $1}'
That shows in which line it was found, which it's the same job that cat -n was doing.
If you don't what to display in which line was found
ls -1v *.sql | awk '/2a\.|3\./'
ygemici
September 6, 2010, 2:40pm
4
like this
# ls -1v *.sql | grep -E '3[^a-z]|2a'
2a.ta.sql
3.view.sql
methyl
September 6, 2010, 4:58pm
5
If you want the most recent version of a particular sql file numbered according to your numbering system as sorted by "ls -1v", this is worth a try.
We use "ls" to cut the list down to those starting with "2." or "2[a-z]." then take the last in the list. The "2>/dev/null" allows for there to be no match.
The patterns got quite painful to avoid accidental matches with say "20a.table.sql" .
version_wanted="2"
ls -1v "${version_wanted}"\.*\.sql "${version_wanted}"[a-z]\.*\.sql 2>/dev/null| tail -1
2a.ta.sql
Thanks Everyone
I have gone with methyl option.
[oracle@ccoshs02xvdbs01 deploy]$ ls -1v *.sql | cat -n
1 1.tab1.sql
2 2.tab1.sql
3 2a.tabl1.sql
4 3.tab1.sql
5 1000.tab.sql
[oracle@ccoshs02xvdbs01 deploy]$ ls -1v "3"\.*\.sql 2>/dev/null| tail -1 | cat -n | awk ' { print $1 } '
1
[oracle@ccoshs02xvdbs01 deploy]$ ls -1v "2"\.*\.sql 2>/dev/null| tail -1 | cat -n | awk ' { print $1 } '
1
[oracle@ccoshs02xvdbs01 deploy]$ ls -1v "2a"\.*\.sql 2>/dev/null| tail -1 | cat -n | awk ' { print $1 } '
With my list command when I gave 2
[oracle@ccoshs02xvdbs01 deploy]$ ls -1v *.sql | cat -n | grep 2 | awk ' { print $1 } '
2
3
Thanks.
---------- Post updated at 10:23 AM ---------- Previous update was at 04:50 AM ----------
[oracle@ccoshs02xvdbs01 deploy]$ ls -lv *.sql | cat -n
1 -rw-r--r-- 1 oracle oinstall 36 Sep 6 13:50 1.tab1.sql
2 -rw-r--r-- 1 oracle oinstall 39 Sep 6 13:51 2.tab1.sql
3 -rw-r--r-- 1 oracle oinstall 40 Sep 6 13:51 2a.tabl1.sql
4 -rw-r--r-- 1 oracle oinstall 39 Sep 6 13:52 3.tab1.sql
5 -rw-r--r-- 1 oracle oinstall 0 Sep 7 10:29 1000.tab.sql
6 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:26 1000a.tat.sql
7 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:26 1001.tat.sql
8 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:26 1002.tat.sql
9 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:26 1003.tat.sql
10 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:37 1004.tat.sql
11 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:38 1004a.ta.sql
12 -rw-r--r-- 1 oracle oinstall 0 Sep 7 15:38 1005.tab.sql
[oracle@ccoshs02xvdbs01 deploy]$ echo $INPUT_FILE
1004
[oracle@ccoshs02xvdbs01 deploy]$ ls -1v "${INPUT_FILE}"\.*\.sql "${INPUT_FILE}"[a-z]\.*\.sql 2>/dev/null| tail -1 | awk -F. ' { print $1 } '
1004a
I want 11 -- line number as the output
Any help please.
ygemici
September 7, 2010, 1:26pm
7
# INPUT_FILE=1004
# ls -lv *.sql | cat -n | grep ${INPUT_FILE}[^\.]* | sed "s/[[:blank:]]*\([0-9]*\) *.*\(${INPUT_FILE}[^\.]*\).*$/\1 -- \2/"
11 -- 1004a