w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » UNIX » Page 1
UNIX/ copy directory to new directory
It's not really possible to do it in 1 command with cp. What you want is for dir3 to already exist when you do your copy. I'm not sure if there's a real reason why you have to do it in 1 command or not. You can certainly do it in one line. mkdir dir/dir3;cp -r dir1/dir2 dir1/dir3

Categories : Unix

Selecting a range of records from a file in Unix
Answer #1: head -n 4930728 myfile.txt | tail -n $(echo "4930728 - 4300846" | bc) Answer #2 - to split the files in 1000 0000 lines: split -l 10000000 myfile.txt ### It will create file like xaa,xab and so on

Categories : Unix

Unix: find all lines having timestamps in both time series?
Let's consider these sample input files: $ cat file1 10-Apr-00 00:00 0 20-Apr-00 00:00 7 $ cat file2 10-Apr-00 00:00 7 21-Apr-00 00:00 3 To merge together those lines with the same date: $ awk 'NR==FNR{a[$1]=$0;next;} {if ($1 in a) print a[$1]" || "$0;}' file1 file2 10-Apr-00 00:00 0 || 10-Apr-00 00:00 7 Explanation NR==FNR{a[$1]=$

Categories : Unix

How to delete extra columns at the end of a CSV file in unix
This can be done with a combination of sed and regex. In particular, the regex for something repeated x times is {x}. So you could do something like this: sed -i 's/,{4}//'

Categories : Unix

PING: command not found
I'm presuming you're wrapping this in a shell script? Is the ping6 command in the search path for the shell you're using to execute that script? Also, stating the obvious: ping6 is also in your path? which ping6

Categories : Unix

unix expr: syntax error
Why are you using expr at all? It's generally used for simple maths / string functions. You can assign the result (stdout) of that expression just using the backticks, or in a more modern way directly with: pingval=$(ping6 -c1 "$url" | tail -1) If you did want to build the shell expression before using, try something like: cmd="ping6 -c 1 '$url' | tail -1" echo cmd | sh

Categories : Unix

script to Rename files in a Directory
This can be achieved with the following: #!/bin/bash dateVar="2014-11-16" for file in *.txt ; do mv $file ${file//.txt/_$dateVar.txt} ; done Explanation: All files in current directory ending with .txt will be renamed to $filename -txt +dateVar+.txt

Categories : Unix

expect to send answers unknown number of times in Unix
Trick is to catch the timeout event from the expect statement. When expect has failed to find the (y/n) prompt within the specified timeout, we can assume that application is ready to become interactive. For example (untested, do not have expect at hand): #!/usr/bin/expect set timeout 20 spawn "./rubyScript" while {1} { expect { "*(y/n)" { send "y " } timeout { break }

Categories : Unix

How to obtain path to changeset predecessor version of file when file is hijacked?
One simple solution is to have a dynamic view with the same config spec as your current snapshot view. While the file state in the snapshot view might not allow to get its predecessor version, the same file referenced in the dynamic view will. cleartool descr -pred -short /view/yourDynamicView/vobs/AVob/path/to/files.c You would still work as usual in the snapshot view, but you would rely on t

Categories : Unix

what does the comma represent listing files in linux?
The character , has no particular meaning while listing files so the root cause looks to be you simply have a file named that way. rm , would then be the more sensible way to remove it.

Categories : Unix

Can 4 file descriptors point to the same file table entry
I do not understand why the if test is needed. Suppose fd is 3, then we just have 4 file descriptor 0, 1,2,3 point the same entry in the file table. Is this a problem? Suppose fd is 0, 1, or 2. Without the test, one of STDIN, STDOUT, or STDERR will be closed. This code is trying to ensure that IN/OUT/ERR are mapped to a known file — probably a redirect to /dev/null opened O_RDWR — so th

Categories : Unix

How can we run reports/queries in MKS through unix
go to mks installation directory location in your unix machine.. Say cd /opt/mks/integrityclient/bin You can see 'si' over there.. Just give command : si help you can see list of executable commands.. Get the syntax for reports.. si reports I guess would be syntax.. Please make sure you run all of above commands from mks installation bin directory.. Hope it helps..

Categories : Unix

Track user when connecting with ssh
dbuser has to connect to localServer to check what local user is doing or done. Since you connect to DBServer with dbuser there is no information about local user withing DBServer. So the short answer is no.

Categories : Unix

Sequence of sorted numbers to ranges
Perl solution: perl -lne 'sub out { print $first == $prev ? $first : "$first-$prev" } # Produce the output. if ($_ != $prev+1 and defined $first) { # Current number not in seq. out(); # Output the previous seq. $first = $_; # Start a new one.

Categories : Unix

How to do recursive edit using SED or any other utility
Change your sed command to, sed 's/,+/,/g' In BRE + would repeat the previous character one or more times. So ,+ matches one or more commas. Replacing the matched commas with a single comma will give you the desired output. Example: $ echo 'A,,,,,,,,,,,,,,,B,,,,,,,C,,,,,,,,,,D,,,,,,,,,,,,E' | sed 's/,+/,/g' A,B,C,D,E

Categories : Unix

How to see and change linefeeds in CSV file in unix
Linefeeds are the expected character at the end of the line for nzload. I think it's carriage returns you must be having problems with. To your first question, you can use "vi -b " to prevent vi from detecting that the file came from DOS and trying to hide the carriage returns that are causing you heartache. If you see "[dos]" at the bottom of the vi screen next to the filename, then you know the

Categories : Unix

ping a given list of servers
You can use a while loop and the bash's read builtin, saying that the file contains comma separated values: while IFS="," read -r id server do ping "$server" done < your_file

Categories : Unix

Replacing gzipped files into zipped files
On most unixes you have gzcat which sends gunzipped output to stdout. However it'll be hard to get that properly zipped in a one-liner (you can do it but you'd have no name for the zipped contents, as they come from stdin). So I guess the best is to make a small script and invoke that from the find. e.g. rudimentary gz2zip.sh (not tested): #!/bin/ksh # input = $1 = gzipped input file name ending

Categories : Unix

sql output as a list in ksh
To loop over the values in a ksh array, you need to use the ${array[@]} syntax: $ set -A rslt 1 2 3 4 $ for i in ${rslt[@]} > do > echo "lvl$i" > done lvl1 lvl2 lvl3 lvl4

Categories : Unix

Extract values from logs
awk is your friend: $ awk -F[][] '{print $(NF-1)}' file 12 10 26 This sets the field separator to either [ or ]. Based on that, the penultimate field contains what you want, so that we print it with $(NF-1). Note sed can also make it with some regex: $ sed -r 's/.*[([0-9]*)]$/1/' file 12 10 26 This catches the last block of digits contained within [] and prints it back with 1. With grep yo

Categories : Unix

Is there a way to automatically upload changed files to a server
entr runs arbitrary commands when files change. It can be installed on Mac OS X via homebrew $ brew install entr Example: $ find /path/to/my/repo | entr echo "Something changed" Just substitute echo "Something changed" with your FTP uploader of choice. The syntax for lftp would be something like this: $ lftp -e "mirror -R {local dir} {remote dir}" -u {username},{password} {host}

Categories : Unix

How do Unix systems keep track of shared memory when processes fork()?
The shared memory region has a reference counter. It gets incremented whenever a process opens the shared memory or gets it by being forked from a process that had it open. It gets decremented when a process closes the shared memory or exits. When the counter goes to 0, the shared memory region is discarded.

Categories : Unix

Dependencies for special make target .DEFAULT not firing
Because .DEFAULT isn't like a regular target. It has very specific behaviour. From the GNU Make Manual: .DEFAULT The recipe specified for .DEFAULT is used for any target for which no rules are found (either explicit rules or implicit rules). See Last Resort. If a .DEFAULT recipe is specified, every file mentioned as a prerequisite, but not as a target in a rule, will have that recipe exe

Categories : Unix

how to check for a pattern at the end of a line and delete new line
You mean like this? $ cat in insert....; update.....; del ete.......; in sert........; $ awk '{if ($0 ~ /;$/) {print} else {printf ("%s", $0)}}' in insert....; update.....; delete.......; insert........;

Categories : Unix

UART 0x0D's becoming 0x0A's
I notice these three flags on the man page for tcsetattr: INLCR Translate NL to CR on input. IGNCR Ignore carriage return on input. ICRNL Translate carriage return to newline on input (unless IGNCR is set). You might want to try explicitly setting INLCR and ICRNL to 0 ?

Categories : Unix

How to print odd numbered fields from a text file using awk in Unix?
? : is the ternary operator provided by awk syntax expression ? value 1 : value 2 if the expression evaluates true, then the value of the ternary expression is value1 else value2 eg assume var =1 output=var==1 ? 10 : 5; here since var==1 evaluates true, the value of ternary operator is 10 hence output becomes 10 Now What {s=s?s FS $i:$i} print s} do s ? evaluates true when s is not empty.

Categories : Unix

Counting hard links to a file in Go
For example, on Linux, package main import ( "fmt" "os" "syscall" ) func main() { fi, err := os.Stat("filename") if err != nil { fmt.Println(err) return } nlink := uint64(0) if sys := fi.Sys(); sys != nil { if stat, ok := sys.(*syscall.Stat_t); ok { nlink = uint64(stat.Nlink) } } fmt.Println(nlink) } Output:

Categories : Unix

awk match how to pass 3rd argument
$ awk -F'"' -v OFS='|' '{print $2, $6, "temp", $4}' file AVERAGE_TIME|0xDZZ|temp|float If that doesn't do what you want then please edit your question to clarify your requirements and add some more truly representative sample input and expected output.

Categories : Unix

AWK to use multiple spaces as delimiter
awk supports a regular expression as the value of FS so you can specify a regular expression that matches at least two spaces. Something like -F '[[:space:]][[:space:]]+'. $ awk '{print NF}' File2 4 3 4 $ awk -F '[[:space:]][[:space:]]+' '{print NF}' File2 3 3 3

Categories : Unix

Delete duplicate headers in awk
You can do this: cp file1 result tail -q -n +2 file2 file3 file4 >> result That is, start with the entire contents of file1, then append from the other files starting with line 2 of each. This way you avoid the need to try to find the extra headers and delete them later. If you prefer, here's another formulation of the same: head -1 file1 > result tail -q -n +2 file1 file2 file3 fil

Categories : Unix

Replace string in every line with a search result using Vi/Vim
Before /home/john/A_2014.jpg /home/john/B_2014.jpg /home/john/C_2014.jpg /home/john/D_2014.jpg Command :%s@v.*/([^/]+)_2014.*@...1...&...@ After ...A.../home/john/A_2014.jpg... ...B.../home/john/B_2014.jpg... ...C.../home/john/C_2014.jpg... ...D.../home/john/D_2014.jpg... As you can see: use @ as delimiter use v to make regex very magic use (...) to capture a group, then reference i

Categories : Unix

meaning of and d when used in ed?
You can test the command passed to "ed" with a simple echo: $ echo $'g/PATTERN/-X,.d ,p' g/PATTERN/-X,.d ,p So in fact the only indicates the end of the first command, and is replaced within your shell. This has no meaning for ed but for your shell. As you said g/PATTERN/-X,.d removes all the line from -X line to current position of the lines matched by PATTERN ,p show all the lines from

Categories : Unix

Reduce cpu cores on Unix system with ant
'<exec executable="sh" os="Linux" spawn="no"> <arg line="-c 'echo 0 > /sys/devices/system/cpu/cpu1/online'" /> </exec>' I am assuming you are able execute the command successfully from the command line. Add some single tics. -c requires a quote enclosed string.

Categories : Unix

How to parse odd numbered fields from a flat file in unix?
You can do this awk awk '{for (i=1;i<=NF;i+=2) printf "%s ",$i;print ""}' file It will print every second columns. cat file one one two one two three one two three four one two three four five one two three four five six awk '{for (i=1;i<=NF;i+=2) printf "%s ",$i;print ""}' file one one one three one three one three five one three five With other separators: cat file one one|two

Categories : Unix

How to delete duplicate column using awk script
If I understood well for each input line all the (value) fields has to be parsed and then all value fields have to be skipped. I assume that all field ends with a comma char except the last one. Here is my suggestion: awk ' { delete a; s="" # Reset tmp values #Search for all (...) fields for(i=1;i<=NF;++i) { if (match($i,/^((.*)),?$/)) { num=$i; gsub(/(^(|),?$)/,"",num);

Categories : Unix

How to replace second existing patteren in unix file
your example does not match your question, so i'll only show how to replace every second match of the given pattern use awk. it's very powerfull tool for command line text processing replace.sh as follow: cat | awk -v search="$1" -v repl="$2" ' BEGIN { flag = 0 } { split($0, a, search) len = length(a) for (f = 1; f < len; f += 1) { printf "%s%

Categories : Unix

Turning row-based data into columns by header
I guess this is more what you wanted: awk -v OFS=" " '/^SET/ {sets[++cols]=$0; set=$0; max_recs=(c>max_recs?c:max_recs); c=0; next} NF{a[cols,++c]=$0} END { for (i=1;i<=cols; i++) printf "%s%s", sets[i], OFS print "" for (i=1; i<=max_recs; i++) { for (j=1; j<=cols; j++) printf "%s%s", a[j,i], OFS print "" }

Categories : Unix

How to calculate sum inside awk command in unix?
You need to remove the field separator from your awk command as you are not using "," to separate fields. awk 'NR >= 2{sum += $7; print $1,$2,$5,sum}' newProcessFile.txt I have removed the counter variable as well as it was not used anywhere.

Categories : Unix

grep for a pattern occuring 2 or 3 times
Group 69 with parentheses: grep -E '(69){3}' Test $ echo "2345679696969" | grep -E '(69){3}' 2345679696969 All together: $ echo "2345679696969" | grep -E '[0-9]{7}(69){3}' 2345679696969 or with a basic grep (thanks Avinash): grep '[0-9]{7}(69){3}'

Categories : Unix




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.