![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with reading file line-by-line, and outputting to a new file | Darkness Fish | Shell Programming and Scripting | 4 | 07-18-2008 07:54 AM |
| Need to serach if a new line character exists on the last line in a file | sunilbm78 | UNIX for Dummies Questions & Answers | 10 | 02-29-2008 02:15 PM |
| perform some checks on file using perl | zedex | Shell Programming and Scripting | 0 | 02-22-2008 03:01 PM |
| Appending the line number and a seperator to each line of a file ? | pjcwhite | Shell Programming and Scripting | 4 | 03-21-2007 01:29 AM |
| Remove header(first line) and trailer(last line) in ANY given file | madhunk | Shell Programming and Scripting | 2 | 03-13-2006 03:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
to perform checks line by line on a file
Hi,
I have a file abc.txt with data like this 1 /test/I want to take out every path from the file and check if its a directory or file. I am trying it with cut with something like this but it doesnt work while read chg_pathPlease help me. Thanks in advance. |
|
||||
|
Assuming the line numbers are not part of the file, you are removing the directory name but leaving a leading slash. This is probably not what you want. (Why would you want to remove the first directory component anyway?) The trivial fix is to use cut -c6- but I suspect you could get a quite different script if you told us why you are doing this and what you are ultimately trying to achieve.
|
|
||||
|
I guess easy way to solve this to find a / character on end of each line. if it is present I would like to treat the path as an input to another command in the check, otherwise ignore.
For example: 1 /test/ ignore 2 /test/file.txt take /test/file.txt to another command 3 /data/ ignore 4 /data/file1.txt take /data/file1.txt to another command and so on.. Another command is same for all. Path starts from 5th position in every line. |
|
||||
|
So the problem you are trying to figure out is how to skip the ones which end with a slash? Code:
cut -c5- abc.txt | while read path; do case $path in */) continue;; esac test -d "$path" && echo "$path" directory || echo "$path" not a directory done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|