unix

How to check file encoding in Linux? Handling multilingual scripts.

Hello Guys, My company has php scripts with texts in different languages (including french, german, spanish, italian and english). Developers decided to use Latin-1 encoding as base for everyone, so this way nobody will override file encoding and corrupt foreign languages in it. (At first some developers used html entities, but this w...

Joining Line Breaks in FASTA file With Condition in SED/AWK/Perl one-liner

I have a data that looks like this > sq1 foofoofoobar foofoofoo > sq2 quxquxquxbar quxquxquxbar quxx > sq3 paxpaxpax pax What I want to do is to join them into one lines: > sq1 foofoofoobarfoofoofoo > sq2 quxquxquxbarquxquxquxbarquxx > sq3 paxpaxpaxpax I tried this code but fail. sed -e 'te' -e 'H;$!d;:e' -e 'x;/^$/d;s/\n//g' Wh...

Perl Oneliner to parse multiple conditions in regex

I have a file that contain lines that looks like this: >AF001546_1 [88 - 462] 1 MGQQ >AF001543_1 [88 - 261] ACGT Not that each line can contain 6 OR 5 fields. What I want to do is to capture Fields 1,2,3(num only), 5(num only) and last field (ACGT or MGOQ strings). So the expected output is this: >AF001546_1 88 462 MGQQ >AF001543_1 ...

Fastest/One-liner way to conditionally remove multiple directories on Unix

What is the shortest way I can write: rm -rfv public/stylesheets public/images public/javascripts and make it conditional, with something like: if [ ! -d public/stylesheets ]; then rm -rfv public/stylesheets; fi ... Just discovered/found a use for command-line conditionals :) ...

Using sockets to read from client side

Hi, I basically have a server set up and I'm accepting new clients(UNIX) and i'm using select() command to wait for activity on file descriptor but I'm not sure how to write from the clients side and then read it on the servers side FD_ZERO(&readfds); FD_SET(server_sockfd, &readfds); FD_SET(STDIN_FILENO, &readfds); while (1) { test...

How would I use a socket to have several processes communicate with a central process?

For my application, I need to have a central process responsible for interacting with many client processes. The client processes need a way to identify and communicate with the central process. Additionally, the central process may not be running, and the client process needs a way to identify that fact. This application will be running...

*nix hosting - redirect download to homepage if referrer doesn't match

I have a software package placed in the root directory of my website. I'd like all visitors which come from other websites to see the homepage first, before they download. How can I do that without using a script? ...

Detect directory changes in unix

How could I track changes of specific directory in UNIX? For example, I launch some utility which create some files during its execution. I want to know what exact files were created during one particular launch. Is there any simple way to get such information? Problem is that: I cannot flush directory content after script execution Fi...

Imports in Python project with doctests

Hi. I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more python files) ... So, I have Python files in couple subdirectories and there are some dependencies between directories as well: tools are used by model, etc. Now my problem is that I want to make doctests for both models ...

UNIX Script for a list of strings find those not in any file

I'm parsing a properties file to get a list of properties defiend. I want to check all the places these properties are used (target dir and subdirs), flagging up any that are defined in the properties file but not used anywhere in the targer dir. Thus far I have FILE=$1 TARGETROOT=$2 for LINE in `grep '[A-Z]*=' $FILE | awk -F '=' '{pr...

Why sed removes last line?

$ cat file.txt one two three $ cat file.txt | sed "s/one/1/" 1 two Where is the word "three"? UPDATED: There is no line after the word "three". ...

Sort characters in a string in UNIX

I would like to sort the characters in a string. e.g. echo cba | sort-command abc Is there a command that will allow me to do this or will I have to write an awk script to iterate over the string and sort it? Thanks ...

Eclipse Editor: How to change file format from Dos to Unix

I am using eclipse editor to work on my remote files it appears that eclipse editor is set to dos file format, I do not know how to find fileformat set in eclipse editor, but I want it to be set on unix file format. How can I set file format options to unix file format in eclipse ? Similar Question to set file format in VIM Thanks. ...

Find all words containing characters in UNIX

Given a word W, I want to find all words containing the letters in W from /usr/dict/words. For example, "bat" should return "bat" and "tab" (but not "table"). Here is one solution which involves sorting the input word and matching: word=$1 sortedWord=`echo $word | grep -o . | sort | tr -d '\n'` while read line do sortedLine=`echo ...

unix command to truncate file contents

can someone help me with unix command to truncate the contents of the files in the directory. I am using Cygwin in windows. ...

Opening an existing process

I am using Eclipse in Linux through a remote connection (xrdp). My internet got disconnected, so I got disconnected from the server while eclipse was running. Now I logged in again, and I do the "top" command I can see that eclipse is running and still under my user name. Is there some way I can bring that process back into my vie...

Applescript conversion to Bash

I would like to make sure that an applescript can be converted to bash. Are there any ideas on how to do this? And if so, I'll place a simple applescript below to give you an example of how the script runs. In more clarity, I simply want a bash script or shell script to do what my applescript is doing. I want it to "enable" or change the...

regular expression help..

I have a file containing a list of file names: esocket.c esocket.h dockwin.cpp dockwin.h makefile getblob . etc... I am looking for a regular expression (preferably unix syntax) to do the following: get lines that have .c, cpp and .h files get lines that don't have a file extension. ...

Program configuration data in Unix/Linux

What is recommended way to keep a user configuration data in Unix/Linux? My programming language is C++. Configuration data will be kept in XML/text/binary format, I have no problem with handling such files. I want to know where can I keep them. For example, in the Windows OS configuration data may be kept in the Registry (old way) or in...

Unix program using the wrong function from shared libraries

Hello, I'm working on refactoring a suite of old utilities and creating a new server that's going to use common code from all of them to unify their functionality and allow external access by remote clients. For each utility, I'm taking the code I need for the server and refactoring it out into a shared library so that the utility and ...