shell script to find noof characters in a file name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers shell script to find noof characters in a file name
# 8  
Old 03-10-2010
Code:
ls -l > temp
awk '{print $ $NF,length($NF)}' temp

Why is there an extra $

just use

Code:
ls -l > temp
awk '{print  $NF,length($NF)}' temp

also if you donot want the total number of files to appear
grep -v 'total'


HTH,
PL
# 9  
Old 03-10-2010
Helooo...Daptal

ls -l > temp
awk '{print $NF,length($NF)}' temp

gives


36 2
21.sh 5
21.sh~ 6
good.sh 7
good.sh~ 8
input 5
new1.sh 7
new1.sh~ 8
temp 4
test1.sh 8
test1.sh~ 9
today.sh 8
today.sh~ 9

But I need like this , so what to do....

-rw-r--r-- 1 krishna users 146 2010-03-10 10:12 21.sh 5
-rw-r--r-- 1 krishna users 146 2010-03-10 10:11 21.sh~ 6
-rw-r--r-- 1 krishna users 49 2010-03-10 12:09 good.sh 7
-rw-r--r-- 1 krishna users 0 2010-03-10 12:08 good.sh~ 8
-rw-r--r-- 1 krishna users 505 2010-03-09 11:42 input 5
-rw-r--r-- 1 krishna users 34 2010-03-08 06:19 new1.sh 7
-rw-r--r-- 1 krishna users 2 2010-03-08 06:15 new1.sh~ 8
-rw-r--r-- 1 krishna users 681 2010-03-10 12:09 temp 4
-rw-r--r-- 1 krishna users 69 2010-03-08 06:08 test1.sh 8
-rw-r--r-- 1 krishna users 2 2010-03-08 05:55 test1.sh~ 9
-rw-r--r-- 1 krishna users 98 2010-03-09 11:42 today.sh 8
-rw-r--r-- 1 krishna users 0 2010-03-09 11:42 today.sh~ 9
# 10  
Old 03-10-2010
Quote:
Originally Posted by krishnampkkm
Helooo...Daptal

ls -l > temp
awk '{print $NF,length($NF)}' temp

gives


36 2
21.sh 5
21.sh~ 6
good.sh 7
good.sh~ 8
input 5
new1.sh 7
new1.sh~ 8
temp 4
test1.sh 8
test1.sh~ 9
today.sh 8
today.sh~ 9

But I need like this , so what to do....

-rw-r--r-- 1 krishna users 146 2010-03-10 10:12 21.sh 5
-rw-r--r-- 1 krishna users 146 2010-03-10 10:11 21.sh~ 6
-rw-r--r-- 1 krishna users 49 2010-03-10 12:09 good.sh 7
-rw-r--r-- 1 krishna users 0 2010-03-10 12:08 good.sh~ 8
-rw-r--r-- 1 krishna users 505 2010-03-09 11:42 input 5
-rw-r--r-- 1 krishna users 34 2010-03-08 06:19 new1.sh 7
-rw-r--r-- 1 krishna users 2 2010-03-08 06:15 new1.sh~ 8
-rw-r--r-- 1 krishna users 681 2010-03-10 12:09 temp 4
-rw-r--r-- 1 krishna users 69 2010-03-08 06:08 test1.sh 8
-rw-r--r-- 1 krishna users 2 2010-03-08 05:55 test1.sh~ 9
-rw-r--r-- 1 krishna users 98 2010-03-09 11:42 today.sh 8
-rw-r--r-- 1 krishna users 0 2010-03-09 11:42 today.sh~ 9
How about this...
Code:
ls -l > temp
awk '{print  $0,length($NF)}' temp

# 11  
Old 03-10-2010
Okk thank you

it works fine,,,
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Shell script to find file type

1. The problem statement, all variables and given/known data: Write a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase: Windows ASCII if the files is an... (4 Replies)
Discussion started by: kwatt019
4 Replies

2. UNIX for Dummies Questions & Answers

Find error in the shell script file

echo "******Select Option:******" echo "1 - script1" echo "2 - script2" echo "3 - script3 " read option echo "You have selected" $option"." if then /scratch/username/script1.sh elif then /scratch/username/script2.sh elif then /scratch/username/script3.sh else echo "Please try again... (12 Replies)
Discussion started by: Dish
12 Replies

3. Shell Programming and Scripting

share a shell script which can replace weird characters in directory or file name

I just finish the shell script . This shell can replace weird characters (such as #$%^@!'"...) in file or directory name by "_" I spent long time on replacing apostrophe in file/directory name added: 2012-03-14 the 124th line (/usr/bin/perl -i -e "s#\'#\\'#g" /tmp/rpdir_level$i.tmp) is... (5 Replies)
Discussion started by: begonia
5 Replies

4. UNIX for Dummies Questions & Answers

Shell script find word from one file and insert in another file

Hi, I am new to shell scripting. I need a bash shell scripts which search and grep a parameter value from input.txt file and insert it in between two semicolon of second line of output.txt file. For example The shell script search an IP address as parameter value from input.txt ... (2 Replies)
Discussion started by: sunilkumarsinha
2 Replies

5. Shell Programming and Scripting

Shell Script Find in File

Right, noob to shell scripting, playing a round for practice, wrote the following but it doesn't seem to work as expected, how could I fix/improve this script? #!/bin/bash #set -v #set -x case $# in 1) echo Searching for $1 in '*'; find . -iname '*' 2>/dev/null | xargs grep "$1" -sl... (3 Replies)
Discussion started by: Pezmc
3 Replies

6. Shell Programming and Scripting

How to find yesterdays file - shell script

Hey guys - i have a script (below) that searches for current files in a particular directory. However i was wondering how to make it search for "yesterdays" file. For instance it looks for a file from yesterday and no older than that. I used stat command to check for file information: ... (6 Replies)
Discussion started by: DallasT
6 Replies

7. Shell Programming and Scripting

writing shell script to find line of invalid characters

Hi, I have to write s script to check an input file for invalid characters. In this script I have to find the exact line of the invalid character. If the input file contain 2 invalid character sat line 10 and 17, the script will show the value 10 and 17. Any help is appreciated. (3 Replies)
Discussion started by: beginner82
3 Replies

8. Shell Programming and Scripting

Bold characters in a file using Shell script

Hi, When I am running below mentioned script then the characters become bold but after opening the same file in Windows, Instead of getting bold characters i am getting some garbage value for \033Kunal Dixit Output in Windows (after ftp the file): but in windows , i am getting My name is... (0 Replies)
Discussion started by: kunal_dixit
0 Replies

9. Shell Programming and Scripting

help removing characters for output file in shell script

hi i'm new to shell scripts and have a small problem i am running a batch converter that returns all flash .flv files in a directory and create a png image from each one the problem i have is the $1 variable , its ok on the first call but on the secound call $1.png , i have extra... (1 Reply)
Discussion started by: wingchun22
1 Replies

10. Shell Programming and Scripting

Shell script to Find file size

Hi, I am writing a script which takes the input file name and concat as a new file by appending a "1" to the file name. However i am not able to get the size of this new file. I am not sure where i am going wrong. Please check the script and help me get this working. #!/bin/sh ... (1 Reply)
Discussion started by: ragsnovel
1 Replies
Login or Register to Ask a Question