Posts
 
Reputation
Joined
Last Seen
Ranked #3K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
52% Quality Score
Upvotes Received
6
Posts with Upvotes
5
Upvoting Members
6
Downvotes Received
6
Posts with Downvotes
6
Downvoting Members
4
6 Commented Posts
0 Endorsements
Ranked #569
~36.9K People Reached
About Me

Shell programmer and author, web designer and coder, cryptic cruciverbalist, chess instructor

138 Posted Topics

Member Avatar for larin83109
Member Avatar for cfajohnson
0
276
Member Avatar for mkoliwad

The best way is to configure the program that creates the file to use the ISO standard date format: YYYY-MM-DDTHH:MM:SS Then the sort command will do the job.

Member Avatar for mkoliwad
0
239
Member Avatar for whizkidash

cpfile=$HOME/bin/cpfile dest=/home/abc for file in /tmp/* do printf 'cp "%s" "%s"\n' "$file" "$dest" done > "$cpfile" Use `find` to list files older than 3 days: find "$dest" -type f -mtime +3

Member Avatar for cfajohnson
0
463
Member Avatar for chriswelborn

If you think you need to know the location of the script, you need to rethink what you are doing. Also, there's no need to use external commands basename and dirname in bash (or any other POSIX shell; use parameter expansion).

Member Avatar for chriswelborn
-1
476
Member Avatar for Akshay nand
Member Avatar for cfajohnson
0
144
Member Avatar for spowel4

Quote the variable references: awk -v FIELDWIDTHS="$FIELDWIDTHS" -v OFS="$OFS" -v INPUTFILE="$INPUTFILE" -v OUTPUTFILE="$OUTPUTFILE"

Member Avatar for cfajohnson
0
561
Member Avatar for Cap'nKirk
Member Avatar for Cap'nKirk
0
225
Member Avatar for zulabc

[indent] To check whether the content of the file contains the string [i].txt[/i]: [CODE] file=content.txt string=.txt if grep -q "$string" "$file" then : ## skip (i.e. do nothing) else : do whatever fi [/CODE] To check whether a filename ends in .txt, use [i]case[/i]: [code] file=whatever case $file in *.txt) …

Member Avatar for Snadiger
0
192
Member Avatar for nano72
Member Avatar for cfajohnson
0
740
Member Avatar for lewashby

No external command is needed: string=123456789012 while IFS= read -n3 z; [[ $z ]] do echo "$z" done <<< "$string"

Member Avatar for cfajohnson
0
202
Member Avatar for timetraveller1992

It's a good idea to post your solution so that others may be helped. Here is your script with the minimum changes needed to get it to work: currenthour=$(date "+%-H") echo "$currenthour" if [ "$currenthour" -ge 12 ] && [ "$currenthour" -le 16 ]; then currenttimeofday="Afternoon" elif [ "$currenthour" -gt …

Member Avatar for cfajohnson
0
183
Member Avatar for johnson gbenga

Use nested loops: ` for i in {0..4} ## you may need $(seq 4) do for j in {a..e} ## or: for j in a b c d e do printf "%s%s\n" "$i" "$j" done done `

Member Avatar for cfajohnson
0
180
Member Avatar for raul8

[QUOTE=raul8;1757613] [code] #!/bin/bash str1="/user/test" echo $str1 echo ${str1}/program [/code] I just want to store [U]"/user/test/program"[/U] in a separate variable. But this "/program" can be anything. Above I wrote the simplest version, for just explaining the issue. [/QUOTE] If you want a separate variable, you need another assignment statement: [code] str1=/usr/test …

Member Avatar for Fest3er
0
132
Member Avatar for niyasc

They are "special parameters" available in all Bourne-type shells. See the man page of your shell for more details.

Member Avatar for adrianfrederic
0
88
Member Avatar for diocode

This doesn't prompt to overwrite; it does nothing in directories already containing index.html: [code] ndx=index.html find . -type d | while read dir do ( cd "$dir" && [ -s "$ndx" ] || mkindex > "$ndx" ## where mkindex is a script to create index file ) done [/code]

Member Avatar for cfajohnson
0
149
Member Avatar for vip011
Member Avatar for cfajohnson
0
166
Member Avatar for maurya10

Get the book, [I]The AWK Programming Language[/I] by Aho, Kernighan and Weinberger. (They wrote the language; its name is their initials.)

Member Avatar for cfajohnson
0
95
Member Avatar for gcclinux

[code] awk -F, ' { printf "%-1s %2s %2s %2s %2s %2s\n", $1 ? $1 : 0, $2 ? $2 : 0, $3 ? $3 : 0, $4 ? $4 : 0, $5 ? $5 : 0, $6 ? $6 : 0 }' "$file" [/code]

Member Avatar for Fest3er
0
163
Member Avatar for gispe

[QUOTE=gispe;833106] Im having a problem with my blog desing: thing is I wanna make a 3-column header, but it wont let me. I've tried resizing the header width and then add 2 more columns, and the header was resized, but the other 2 columns didn't appear, so I gues I …

Member Avatar for richard_nev
0
268
Member Avatar for dancks

> I was supposed to write a program that reads and writes phone numbers of people to a file called phones.txt. The reading part works. The write part doesn't. I tried to use the cat command because I thought doing cat >> file.txt would simply append to a file. What …

Member Avatar for dancks
0
373
Member Avatar for pfm200586

[QUOTE=pfm200586;1676335]Ok guys I made the script working but there is one last problem which is the AM and PM I coded the following if statement: [code] if [ $Start -gt 12 ] then Start=`expr $Start -12` "PM"[/code] [/QUOTE] [indent] There's no need to use an external program if you are …

Member Avatar for L7Sqr
0
916
Member Avatar for nikita.

[QUOTE=nikita.;1685056]Hi , I want to run a shell script which is present in another user's id after switching it to that user in the same script. but it is not taking it. I m using the su command for that. [code] su - user1 -c "./${HOME}/script1.sh" [/code] it just says …

Member Avatar for nikita.
0
172
Member Avatar for nikita.

The [I]ftp[/I] command is not designed for use in scripts; it is intended for interactive use. For scripting, use the [I]ncftp[/I] family of commands. (There are also some others, I believe, that are made for scripting.)

Member Avatar for nikita.
0
208
Member Avatar for aFg3

[indent] The [i]setterm[/i] command is not standard. Standard, but not implented consistently across platforms is [i]tput[/i]. Both of those commands are designed to work with any type of terminal (as specified by the TERM variable). However, the plethora of terminal types has, for all intents and purposes, been reduced to …

Member Avatar for cfajohnson
0
5K
Member Avatar for SakuraPink

[indent] Do you know where the files, job_1.e and job_2.e, are? If so, why use [i]find[/i]? [code] for file in job_*.e ## adjust path if necessary do if grep -q "Finished with all tasks." "$file" then : line found; do something else : line not found; do something else fi …

Member Avatar for cfajohnson
0
130
Member Avatar for earlybirdsean

When referring to shell scripting, one usually means a Unix shell, and more specifically, one derived from Steven Bourne's 1978 shell. A number of extensions to the Bourne shell were introduced by David Korn in the Korn shell (ksh, ks88 and ksh93). The Korn extensions were the basis of the …

Member Avatar for cfajohnson
0
196
Member Avatar for Shruti4444

[QUOTE=Shruti4444;1528087]Trying to code a shell script for a program testing. i need to check for the existence of particular word in outfile and then proceed further, which i am not able to do. I have wrote the following code. Please tell the corrections.. The control does not pass to the …

Member Avatar for IIM
1
133
Member Avatar for lu2lu

[QUOTE=griswolf;1481483]$@ is a built in variable that holds [B]all[/B] the command line arguments passed to your script. $1 is just the first command line argument. Here's a useless script that illustrates use of $@[CODE]# Usage: bash thisfile anyfile [anyfile...] for fname in $@; do [/CODE] [/QUOTE] [indent] That will break …

Member Avatar for lu2lu
0
166
Member Avatar for JonSmith

[QUOTE=griswolf;1522396]Using bash: This worked fine for my baby test. [/QUOTE] [indent] But it will fail in several places if any filenames contain whitespace. [/indent]

Member Avatar for JonSmith
0
179
Member Avatar for pichels

[QUOTE=pichels;1510646] Was wondering if I could get help with a shell script I am writing to read in 10 -20 directories from a filesystem and then pause, press any key and then read in another 10 or 20 directories and pause again until I read them all. [code] #!/bin/bash DIRS="/data/cusserv/" …

Member Avatar for cfajohnson
0
407
Member Avatar for tig2810

[indent][code] var='"THIS" "THAT" "THIS AND THAT" "THIS AND THIS"' eval "set -- $var" for i do echo $i done [/code] [/indent]

Member Avatar for cfajohnson
0
145
Member Avatar for lids05

[QUOTE=lids05;1482162]I am a novice, so please don't be too technical ! I have written 3 separate scripts which all work OK. I now need to merge them into one big script. I would like to introduce a runtime parameter, to allow me to restart at script2 or script3. I would …

Member Avatar for lids05
0
86
Member Avatar for dark3lf

[indent] It works for me. But you could simplify the code (there's no need for external commands): [code] LF=' ' mountPoint=`df -h "$pth"` mountPoint=${mountPoint#*"$LF"} [/code] Or, if you want to use a Bourne shell rather than a standard Unix shell: [code] mountPoint=`df -h "$pth" | { read; read -r x; …

Member Avatar for thekashyap
0
202
Member Avatar for Dongalor

If you need to know where the script is, there is something wrong with your algorithm. Scripts should be in a directory in your PATH, and you should never need to know where it is.

Member Avatar for griswolf
0
239
Member Avatar for brick79
Member Avatar for linux.buzz

If you want to use awk, there is the split() function: [code] awk -v t=3m1.057s 'BEGIN { split(t,d,/[m.s]/); minute=d[1]; second=d[2]; millisecond=d[3]; print minute, second, millisecond; }' [/code] Using the shell: [code] ( t=3m1.057s IFS=m.s set -f set -- $t set +f minute=$1 second=$2 millisecond=$3 printf "%s %s %s\n" "$minute" "$second" …

Member Avatar for cfajohnson
0
146
Member Avatar for vajrajames

[code] #!/bin/bash ## Name: randstring ## Synopsis: randstring [ -n NUM ] [ -l LENGTH ] [ -c CHARSET ] ## Author: Chris F.A. Johnson ## Defaults: length=4 num=4 charset=abcdefghijklmnopqrstuvwxyz rand_char() { RAND_CHAR=${charset:$RANDOM % ${#charset}:1} } rand_word() { local string= while [ ${#string} -lt $length ] do rand_char string=$string$RAND_CHAR done …

Member Avatar for cfajohnson
0
122
Member Avatar for ammayi67
Member Avatar for suavedesign
Member Avatar for cfajohnson
0
690
Member Avatar for mojo1979

[INDENT][CODE] dir=/path/to/1TB/drive IFS=$(printf "\n") zip mdf $(find "$dir" -name '*.mdf') find "$dir" -name '*.mdf' -exec rm {} + [/CODE][/INDENT]

Member Avatar for cfajohnson
0
102
Member Avatar for tcollins412

[QUOTE=FutureWebDev;1419184]If its only going to be for this one page try using an internal CSS stylesheet with the following: [B]CSS[/B] [CODE]#tdleft { width: 100px; height: 100px; background-color: green; border-radius: 10px 0px 0px 0px; -moz-border-radius: 10px 0px 0px 0px; -webkit-border-top-right-radius: 0px; -webkit-border-bottom-right-radius: 0px; -webkit-border-bottom-left-radius: 0px; } #tdright { width: 100px; height: …

Member Avatar for shaya4207
1
175
Member Avatar for maketick123

Don't use the HTML (or XHTML) tutorial at w3schools: [url]http://cfajohnson.com/webdesign/w3schools/[/url]

Member Avatar for Arkinder
0
154
Member Avatar for manish250

[QUOTE=manish250;1403437]hello all i hav a script when i print it's execution in some line there is #+ in the starting and somewhere there is #++.can anyone plz tell me about these[/QUOTE] [indent] Please show the script. I have no idea what you are talking about. Are #+ and #++ in …

Member Avatar for cfajohnson
0
133
Member Avatar for rmsagar

[indent][code] IFS=$'\n' names=( $(find /opt/scripts/ -type f -name "properties.*") ) IFS=$' \t\n' printf "%s\n" "${names[@]}" [/code][/indent]

Member Avatar for cfajohnson
0
110
Member Avatar for vegaseat
Member Avatar for programmer321

[QUOTE=dev_272000;1161375][CODE]#! /bin/bash ######## Created By - R.Wesley Dev Andrew ######### date=`date +%d-%m-%Y` #echo "Please input date in format dd-mm-yyyy" #read date day=`echo $date | awk -F\- '{print $1}'` month=`echo $date | awk -F\- '{print $2}'` year=`echo $date | awk -F\- '{print $3}'` [/CODE] [/QUOTE] [indent] There no need for awk, …

Member Avatar for cfajohnson
0
3K
Member Avatar for sivaranga001
Member Avatar for flynismo
Member Avatar for ~s.o.s~
0
135
Member Avatar for chrisb76
Re: Help

You need an expression inside [[ ... ]]. Read the bash man page. A better contruct would be to use a case statement. It's not clear from your script exactly what you are trying to do. Please expand.

Member Avatar for cfajohnson
0
83
Member Avatar for sivaranga001
Member Avatar for cfajohnson
0
127

The End.