spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » UNIX » Page 1
Awk with combination of cut and if
You could do it with: awk '$3 ~ /:0$/{print $4-1;next}{print $4}' test.txt -0.238 0.754 0.848 0 0.851 If the 3rd column ends with :0 ($3 ~ /:0$/) then print the 4th column minus 1; else print the 4th column.

Categories : Unix

Rename multiple files based on count
With standard UNIX you'd need more than one command, e. g. count=10 for file in File_*.txt do augend=`echo $file|sed 's/File_(.*).txt/1/'` mv $file File_`expr $augend + $count`.txt done But if you have a system with this rename available, you can rename 's/File_(.*).txt/"File_".($1+$ENV{count}).".txt"/e' File_*.txt (assuming count has been exported to the environment) or rename 's/Fil

Categories : Unix

How to count words in url
grep -Po 'resource/K[^_]*(?=_)' urls.txt | uniq -c | awk '{print $2" "$1}' Output: Duncan 1 Ruth 1 Abbas 1 John 2 grep -Po '_K[^_]*$' urls.txt | uniq -c | awk '{print $2" "$1}' Output: Trussell 1 Reynolds 1 Noyan 1 Dowdell 1 Du 1 If you want you can replace | uniq -c | awk '{print $2" "$1}' by | awk '{count[$1]++}END{for(j in count) print j, count[j]}'.

Categories : Unix

add julia to path for easy start program
I figured out the solution, add following command to profile and refresh the terminal: alias julia='exec /Applications/Julia-0.3.2.app/Contents/Resources/julia/bin/julia'

Categories : Unix

Piping the output of a command, but only if the output is non-empty
I think you can find the answer in this link. Anyway you can put this function in the magical part: pipe_if_not_empty () { head=$(dd bs=1 count=1 2>/dev/null; echo a) head=${head%a} if [ "x$head" != x"" ]; then { printf %s "$head"; cat; } | "$@" fi }

Categories : Unix

ksh script variables run differently in nohup
My guess is this difference has something to do with the seemingly innocuous sourcing operator(.) or the current directory operator(./) at the beginning of your script. nohup - is no hangup to make the process not to hangup when the user log outs > prcsstst.log & - redirects to log file and backgrounds the process which rules out them as contenders for the difference in output. Please

Categories : Unix

Search files and run a script on every result
I think a while loop is the best way to handle these situations: while IFS= read -r file do awk '...' <(zcat "$file") done < <(find . -type f -name "*gz") You have a find command that is sent to a while loop. This way, you can process each file separatedly. Then, it is a matter of performing a basic awk '...' <(zcat "$file") or zcat "$file" | awk '...'. In your case: while IFS

Categories : Unix

Telneting to Solaris11 on VirtualBox from host computer
You can't access a VM service when using NAT unless you configure a reverse forwarding port. The simplest workaround is to switch your virtual NIC from NAT to bridge mode in which case your VM will be visible from your LAN.

Categories : Unix

unix ftp script to get latest file from server
This is really pushing the FTP client further than it should be pushed, but it is possible. Note that the LS_FILE_OFFSET might be different on your system and this won't work at all if the offset is wrong. #!/bin/sh HOST='1.1.1.1' USER='user' PASSWD='pass' DIRECTORY='.LogbookPlus' FILES_TO_GET=1 LS_FILE_OFFSET=57 # Check directory_listing to see where filename begins rm -f directory_listing #

Categories : Unix

Print next N lines containing ":" after matched word - using oneliner
Assuming OPEN only appears on the server lines this should work. lltstat -nvv active | awk -v HOST_VAR=$HOST_VAR '$0 ~ HOST_VAR{a=1; next} a&&/OPEN/{exit} a{print}'

Categories : Unix

how to write db2 query with join and export clause in unix
First, you need to test the query works as desired. Please try to run just the select. If there are many rows, you can limit the result with fetch first x rows only db2 " SELECT PRICE.PRC_SECURITY_ID, (decimal(PRICE.PRC_PRICE)), PRICE.PRC_CURRENCY,PRICE.PRC_CURRENCY FROM RISKAPP.PRICE as PRICE inner join RISKAPP.SECURITY as SECURITY on PRICE.PRC_SECURITY_ID = SECURITY.SEC_SECURITY_ID and SEC

Categories : Unix

Unix Loop if Condition and exit comand
If you only want the "ENDING SCRIPT SUCCESSFULLY" message to appear if files were successfully deleted, not if an invalid path was given you could just move the last two echo lines up to the end of the else statement like this: else echo -e " FILES DELETED FROM THE "$path" DIRECTORY --" >> $LOG_FILE find $path -type f -mtime +$DAYS_BFOR -printf "%TY-%Tm-%Td %kKB %p

Categories : Unix

UNIX programming: Head command
You almost got it right. It's the ls that needs to be enclosed in backticks so that its results are fed as filename arguments to head. To get the first line of all the text files in the current directory you would use: head -n 1 `ls -Q *.txt` To get the files in subdirectories, you could use ls and grep like you have (just make ls recursive, and make grep search for .txt in the end of each line

Categories : Unix

How to find lines including two letter words using grep
You can use the "word mode": $ cat file.txt A AB CDE ABD KJSD SD DAD LD $ grep -w '..' file.txt A AB CDE SD DAD LD From man grep: -w, --word-regexp Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constitu

Categories : Unix

Capturing kill code of go process?
You can catch signals using the os/signal package. You can catch SIGINT with code something like this: import ( "os" "os/signal" ) ... // the signal module will lose notifications if the channel is not ready to receive, so give it a buffer ch := make(chan os.Signal, 5) go func() { for sig := range ch { // interrupt signal received os.Exit(0) } }() signal.Notify(c

Categories : Unix

why normal User can't change password of others if suid bit is set on passwd
suid bit doesn't make something run as root. It merely allows something to make the setuid system call, to elevate it's privileges. passwd requires root privileges to update user credentials. It does this quite cautiously though - it starts in a user context, verifies stuff, and then escalates privileges to make the system change. It being set setuid doesn't have any bearing on this - it merely

Categories : Unix

How To Run Multiple "awk" commands:
Your first attempt failed because you were trying to call awk in an awk script, and your second attempt failed because the bash process substitution, <(...), is not defined by POSIX, and is not guaranteed to work with /bin/sh. Here is an awk script that should work. #!/usr/bin/awk -f BEGIN { if (ARGC < 3) exit 1; ct = "cat "; gz = "gzip -dc " f = """ ARGV[1] """; c = (f~

Categories : Unix

unix get list of all occurences of string between two quotes
Try this: tr -d ' ' < file | sed -r -e 's/(=[^=]+)=/1 /g' | sed -n 's/.*=//p' Step by step: Original: sdlcb@Goofy-Gen:~/AMD$ cat file "Logs timestamps are good =timstamp= for new files check data= new-char= the data is changed every =time and= so on and i need all =data=" 1: sdlcb@Goofy-Gen:~/AMD$ tr -d ' ' < file "Logs timestamps are good =timstamp= for new files check data=new-cha

Categories : Unix


Recently Add
Use a file with row numbers to delete rows in a separate file
Awk with combination of cut and if
Rename multiple files based on count
How to count words in url
add julia to path for easy start program
Piping the output of a command, but only if the output is non-empty
ksh script variables run differently in nohup
Search files and run a script on every result
Telneting to Solaris11 on VirtualBox from host computer
unix ftp script to get latest file from server
Print next N lines containing ":" after matched word - using oneliner
how to write db2 query with join and export clause in unix
Unix Loop if Condition and exit comand
UNIX programming: Head command
How to find lines including two letter words using grep
Capturing kill code of go process?
why normal User can't change password of others if suid bit is set on passwd
How To Run Multiple "awk" commands:
unix get list of all occurences of string between two quotes
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.