Questions tagged [unix]

18571 questions
1

votes
3

answer
316

Views

How to print first word of first line and last word of last line in unix in a file

Suppose there is a file file1.c It has 100 lines . I need to print first word and last word of that file.
user265906
1

votes
2

answer
42

Views

Start two never ending python scripts

Is there a proper way to start two python scripts that will never end? I have a Bash Script.. I just want it to start two python server applications on different ports. But obviously as I get to the first python command, it will loop forever is there a way to kill these two python scripts when you k...
billybob2
1

votes
3

answer
57

Views

grep for a variable that contains “+”

Trying to pickup the second row using grep and it dosent work if it has a '+' character i have tried with fgrep & instead of -P tried with Fx or x and -w but none of them worked. File prereq.txt contains this : WS+1 whatever 2222 WS--1...
Yashas K.M
1

votes
2

answer
48

Views

Reproducibility issue of an openMP output

I am going through openMP tutorials and as I progressed, I have written an openMP version of a code that calculates PI by using an integral. I have written a serial version so I know the serial counterpart is ok. Once the openMP version completed, I noticed that everytime I run it, it gives me a di...
Fays
1

votes
2

answer
46

Views

RegEx for a multiple line search and replace using sed

I need to have a RegEx that finds a \n in the middle of a line as a start point, anything before is random, and replace after 15 digits and 49 alpha on the second line. I need to replace all that by blanks, but the second line needs to join with the first one. Attempt sed -r -e '{N;s/\n[[:digit:]]{1...
Eric Charbonneau
1

votes
2

answer
69

Views

Get Windows username from Bash Unix shell?

Is there a way to get the Windows' username of the user who's connecting to a specific Unix environment, using always the same server's credentials, directly in Bash? Some background There is a population of N users, who may connect to M different Unix environments always using the same credentials...
Matteo NNZ
1

votes
2

answer
32

Views

how to insert line break after a specific string?

I have a file with the following text, I want to make a line break, after the S. character i have this 1900-01-01 00:00:00|1|S|S|S|S.1900-01-01|S.1900-01-01 00:00:00|1|S|S|S|S.1900-01-01 00:00:00|1|S|S|S|S. i want 1900-01-01 00:00:00|1|S|S|S|S. 1900-01-01|S. 1900-01-01 00:00:00|1|S|S|S|S. 1900-01...
Brayan Pastor
0

votes
0

answer
3

Views

Not able to create local directory in EMR by user 'livy'

I am submitting a pyspark job into EMR cluster from a AWS Step Function through apache livy. The pyspark job has Unix shell commands being fired. Within test.py, subprocess.call(' echo $USER', shell=True, stdout=None, stderr=None) subprocess.call(' mkdir /mnt/data', shell=True, stdout=None, stderr=...
Parijat Bose
0

votes
0

answer
7

Views

Converting ASCII file to UTF-8 in unix

I have a csv file that I transfer from 1 server to another using sftp. This file is in text/plain; charset=utf-8 encoding and contains special characters such as Ñ. Upon transfer the file encoding is being changed into ascii and the Ñ becomes unreadable. How to convert it back to UTF-8? I've trie...
user2058738
1

votes
1

answer
216

Views

Identify Process Holding Lock on File

I have a file named parent.control i just create it in my program, its just a text file. Sometimes other processes open and lock this file. I would like to identify which process(es) has locked it. Is this possible? I'm using Ubuntu but looking for a cross *nix solution.
Noitidart
-1

votes
0

answer
16

Views

Making a new column out of specific lines from within a file?

I am trying to solve the following problem but several attempts have failed to get it right. Supposing I have the following in a file: a,b,c d,e,f g h I need some way to add g and h as a third column so that the file looks like this: a, b, c, g d, e, f, h Thanks for you help.
John Davy
1

votes
1

answer
682

Views

Unable to create folder on Mac (El-Capitan), permission error

This simple error has me stumped: (0)[email protected]# mkdir ruby-2.0.0-p645 mkdir: ruby-2.0.0-p645: Operation not permitted (1)[email protected]# pwd /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 (0)[email protected]# Here is all the debug info I can think of...
Kashyap
1

votes
2

answer
536

Views

psinfo_t solaris does not contain full process name in its field

Not getting full process name in psinfo_t struct's field pr_fname while reading process info from psinfo data file(/proc/%d/psinfo) into struct psinfo_t from procfs.h in solaris. Full psinfo_t struct definition is present on below site: http://docs.oracle.com/cd/E19253-01/816-5174/6mbb98ui2/index.ht...
mSatyam
1

votes
1

answer
392

Views

R - how to convert JavaScript timestamp to human date time with as.POSIXct?

How can I convert a timestamp in this format to human date? I create the timestamp using javascript: Date.now(); Output example: 1468833354929 Then I store it in a db. So when I try to convert it with R: date
laukok
1

votes
5

answer
45

Views

How to add “/1/” as a line number in a txt file?

In Unix I want to add slash before and after the line number in a .txt file this command only shows the line numbers cat -n txt.file this: Tony Alpha Bravo to this: /1/ Tony /2/ Alpha /3/ Bravo
user10813205
1

votes
2

answer
47

Views

Splitting the first column of a file in multiple columns using AWK

File looks like this, but with millions of lines (TAB separated): 1_number_column_ranking_+ 100 200 Target 'Hello' I want to split the first column by the _ so it becomes: 1 number column ranking + 100 200 Target 'Hello' This is the code I have been trying: awk -F'\t' '{n=split($1,a,'_');for (...
Steveman30290
1

votes
5

answer
50

Views

UNIX average of specific employee as per designation

This is an example of a text file to be given as input Name,Designation,Salary Hari,Engineer,35000 Suresh,Consultant,80000 Umesh,Engineer,45500 Maya,Analyst,50000 Guru,Consultant,100000 Sushma,Engineer,30000 Mohan,Engineer,30000 My code should be able to run find the average salary of particular emp...
John Doe
1

votes
1

answer
35

Views

Write content into a file with bash script

I'm trying to create a bash script in order to daemonized celeryd task. In my bash script, I need to create some files and add content. This content have a variable given by user named $app_name with read method and some others variables in the content. Issue: When I copy the content located in my b...
Essex
1

votes
2

answer
85

Views

Need first two characters from a file and make sure that they both aren't below 6 then return line

I have a text file like this 17 Blue 45 Purple And I need to make sure the first two digits aren't both less than the number 6 and then print them. So, for example, the first line would print since the first digit 1 is lower than 6 and the second digit 7 is higher than 6, so they aren't both lower t...
serenitynow13
1

votes
2

answer
71

Views

Can I grep multiple AND arguments in if else?

I'm trying to grep multiple arguments in shell. I put orders like ./script arg1 arg2.. argN And I want them to act egrep -i 'arg1' mydata | egrep -i 'arg2' | ... egrep -i 'argN' | awk -f display.awk in order to match patterns in AND format. What's wrong in my process? Is it even right to code like...
Yusun Lim
1

votes
2

answer
798

Views

Don't understand CIRCUMFLEX use in this UNIX command ls -L | grep -v ^zip

ls -L | grep -v ^zip What i understand from this command is, it is doing a listing and piping the output to a grep command which performs grep on the received output file list to select any file with file name not containing text 'zip' and any file with file name containing text 'zip'. If this is co...
Oh Chin Boon
1

votes
1

answer
268

Views

Getting the wrong date from cell using PHPExcel

I'm using PHPExcel and trying to get the date values from the cells, but for some reason they give me the wrong date. $dt_column = $obj_sheet->getCell('A1'); $unix_date = PHPExcel_Shared_Date::ExcelToPHP($dt_column); $date = gmdate('Y-m-d 00:00:00', $unix_date); The file is in .xlsx format....
Theodor3gabriel
1

votes
0

answer
69

Views

After changes in pam crontab stop working

I have made changes in : cat /etc/pam.d/common-session-noninteractive sudo vi /etc/pam.d/cron sudo vi /etc/security/limits.conf after rebooting system crontab stop working when I check syslog it shows below error: PAM (cron) illegal module type: ession cron[4936]: Permission denied
Sandesh Dumbre
1

votes
0

answer
119

Views

Add new column in file using sed

I am trying to add a new column in a file and using below command got from another Stack overflow post: sed 's/$col/$col$FSEP$value/' $file > ${file%.*}'_m.txt' col=1 is column number, value=20171231 is the and FSEP=| is the field seperator. current data: '01 '|'name '|'address '|' phone number...
Explorer
1

votes
1

answer
39

Views

Want to write customized error and output function in shell script

I want to pass the standard error and standard output to userdefined function to write the custom logs OutputLogFile='OutputLogFilepath' ErrorLogFile='ErrorLogfilePath' //user defined function OutputLog() { echo $(DateTimeForLog)-$ScriptName-”information”-$1 >> $StdOutPutlogFile }...
Suganya
1

votes
0

answer
232

Views

grep command in json file

I am using grep command in a multiple json file which has content like this: 'Verdict': { 'Severity': '-1', 'Description': 'Some description' Reputation' } I want look for word Verdict and if it matches ,get the Severity number. So far I used: 'grep -A 2 -R \'Verdict\' path\to\file*.json\'|grep Se...
Piku
1

votes
0

answer
15

Views

Router dies on using Google Meet or Hangouts

I'm using Arch Linux on Lenovo Ideapad 520. Whenever I try to use Google Meet, my tplink router crashes and internet connection dies. I'm required to reboot the router for getting the connection back. Any help?
Souvik Haldar
1

votes
1

answer
52

Views

Bash Script Unstable Result

I have bash script and I put in the crontab. It runs every 10 minutes. When I run it manually, it gives perfect results. It creates '.tmp' files and these '.tmp' files are not empty, but Crontab results are not as I expected. it only creates '.tmp' files. Contents of '.tmp' files are empty. In this...
Umut TEKİN
1

votes
0

answer
379

Views

Running process 'as root' with setuid bit not working as expected - operation not permitted?

I have a program that captures network traffic off a network interface. (It's a C program sitting on libpcap.) I'm running Fedora 26. When I run the program as root, things look great: [craig ~]$ sudo su - [root ~]$ /home/craig/mybinary (output is as expected) But, when I run the program as myself (...
Craig Otis
1

votes
1

answer
59

Views

gcc showing errors from system library. -isystem doesnt work

Here is a simple (Deliberately wrong) c++ hello world program(https://pastebin.com/Cehm9yLx) #include using namespace std; int main() { int a; cout >> 'Hello World! Welcome!'
user9180468
1

votes
0

answer
278

Views

Cannsandra Driver & jnr-Unixsocket - java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider

I am using cassandra and jnr-unix socket in my project and both uses jnr-ffi. Not getting any error in my local, but getting error in test env. The versions are, Cassandra version - 3.3.2 jnr-unixsocket - 0.12 Error happens on calling UnixSocketChannel.open() from my code. Code from the hierarchy,...
user1578872
1

votes
1

answer
66

Views

sh script to replace text in multiple files

I am trying to replace every occurrence in a .prm file of the string '/net/origin/devdata1/slin' with '/tools/common/test/HATS' in over a hundred files using sed. I think I am having trouble with the proper syntax for a for loop that loops through different files in a directory(/home/AutoTest), and...
dhboots
1

votes
2

answer
213

Views

Clearcase copy files and folders to another location

I have one requirement where i need to copy Clearcase particular version's directory and subdirectory files to another location via python. When I used shutil.copytree function it copies the folders files but the problem is it creates the files as directory type. ex: source = 'testfolder/@@/main/1'...
user2660409
1

votes
1

answer
41

Views

read non-formatted column value

I am trying to read all values for 'Description 4' column. I can read it if all values are in same line and none of the values are empty but in below case some are empty values and some values are not oriented in same line as others. Please suggest how can i just pull all values below 'description 4...
ankitpandey
1

votes
3

answer
62

Views

replace variables of a file with reference to values in another file

I have two files file1.txt variable1=string1 with spaces characters variable2=string2 with spaces characters variable3=string3 with spaces characters file2.txt sometext1 textvariable1 sometext2 sometext3 variable2 sometext4 sometextcharactersvariable1 charactersvariable3 sometext5 variable2 ...........
venkatsai
1

votes
1

answer
49

Views

Automating build installation process

I work on a SaaS based product of my company which is hosted on private cloud. So every time a fresh BOM package is available by the DEV team. In the common share folder , we- the testing team installs the build on our application servers (3 multi node servers, with one being primary and the other t...
user3834797
1

votes
0

answer
66

Views

How to wait until mqueue creation is available?

I have to write program that heavily uses queues from mqueue.h. The problem is it can easily reach /proc/sys/fs/mqueue/queues_max limit which I cannot change. Is it possible to wait until creation of new queue is available without hard spinning? I mean something like do { desc = mq_open(name, O_CRE...
radrow
1

votes
1

answer
511

Views

Converting from UNIX Timestamp to datetime results in OSError: [Errno 22] Invalid argument

I'm retreiving an endpoint from an API that comes back as: Date(1516367982230) I named this SentDate in my script. The number between the brackets is a UNIX time stamp. I want to convert this to a normal date and time so I used a function I found on stackoverflow: SentDate = dt.datetime.fromtimestam...
Henk de Vries
1

votes
0

answer
30

Views

Compare 2 booleans and declare to variable

My problem is to compare 2 booleans and declare result into variable. variable=`function argument1` # 1 variable=`$variable || function argument2` if [ $variable == 'true' ] ; then do one else do another fi I need to execute function with argument2 and this function return true or false and need...
Андрей Ка
1

votes
1

answer
131

Views

Write logs to Unix box in Spring Boot Application

I want to deploy my spring boot application to a unix server and write logs to a specific directory on the server. Right now, I am able to write logs to my a log file in my spring boot app but it is inside my project. So my project exists in Project/myApp and logs are written to Project/myApp/logs/m...
T. Phillips

View additional questions